While working tonight on some query work I came across the following situation. Bare with me as I build up all the pieces of the final two queries, then notice how the subqueried version fails, but the substituted version doesn't. What am I missing in here:

mysql> SELECT parent_path FROM category WHERE id=2;
+-------------+
| parent_path |
+-------------+
| 1           |
+-------------+
1 row in set (0.00 sec)

mysql> SELECT CONCAT((SELECT parent_path FROM category WHERE id=2), ",2");
+-------------------------------------------------------------+
| CONCAT((SELECT parent_path FROM category WHERE id=2), ",2") |
+-------------------------------------------------------------+
| 1,2                                                         |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM category WHERE parent_path=CONCAT((SELECT parent_path FROM category WHERE id=2), ",2");
Empty set (0.00 sec)


mysql> SELECT * FROM category WHERE parent_path="1,2";
+----+------------+--------+----------+-------+-------------+------+
| id | name       | parent | children | leafs | parent_path | seq  |
+----+------------+--------+----------+-------+-------------+------+
|  3 | Developers |      2 |        0 |     0 | 1,2         |    0 |
|  5 | Users      |      2 |        0 |     0 | 1,2         |    0 |
+----+------------+--------+----------+-------+-------------+------+
2 rows in set (0.00 sec)

mysql> SELECT * FROM category WHERE parent_path LIKE CONCAT((SELECT parent_path FROM category WHERE id=2), ",2");
Empty set (0.00 sec)


mysql> SELECT VERSION();
+-------------+
| VERSION()   |
+-------------+
| 4.1.5-gamma |
+-------------+
1 row in set (0.00 sec)


-- Ryan Sommers [EMAIL PROTECTED]

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to