Re: Liberating Dependent Subqueries
Posted by:
mnf
Date: December 01, 2006 09:35AM
Good idea, but doesn't work for me.
mysql> CALL constify('SELECT MAX(i) FROM shn1 GROUP BY n', @result);
Query OK, 0 rows affected (7.62 sec)
mysql> SELECT * FROM shn1 WHERE i IN ( @result );
+---------+---+------------+---+
| i | n | t | v |
+---------+---+------------+---+
| 7501830 | 1 | 1163553309 | 0 |
+---------+---+------------+---+
1 row in set (0.00 sec)
The problem is @result variable in "WHERE i IN (@result)" part. "IN" sees @result not as a list, For example
mysql> SET @result='1, 2, 3';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @result;
+---------+
| @result |
+---------+
| 1, 2, 3 |
+---------+
1 row in set (0.00 sec)
mysql> SELECT * FROM shn1 WHERE i IN ( @result );
+---+---+---+----+
| i | n | t | v |
+---+---+---+----+
| 1 | 1 | 0 | -1 |
+---+---+---+----+
1 row in set (0.00 sec)
mysql> SELECT * FROM shn1 WHERE i IN ( 1, 2, 3 );
+---+---+---+----+
| i | n | t | v |
+---+---+---+----+
| 1 | 1 | 0 | -1 |
| 2 | 2 | 0 | -1 |
| 3 | 3 | 0 | -1 |
+---+---+---+----+
3 rows in set (0.00 sec)
What am I missing?
Thsnks in advance,
Michael
Subject
Views
Written By
Posted
14650
November 27, 2006 05:50PM
3896
November 28, 2006 12:57AM
3545
November 28, 2006 03:09AM
3483
November 28, 2006 06:29PM
4258
November 30, 2006 05:39PM
Re: Liberating Dependent Subqueries
3161
December 01, 2006 09:35AM
2868
December 03, 2006 06:21PM
2883
December 03, 2006 08:18PM
2895
December 05, 2006 06:11AM
4184
December 05, 2006 08:43AM
3934
December 07, 2006 06:26AM