p
By: a guest | Mar 13th, 2010 | Syntax:
None | Size: 2.19 KB | Hits: 57 | Expires: Never
This is the table.
+-------+----------+--------------------------------+-----+---------+------------+
| catid | parentid | catname | pos | enabled | timestamp |
+-------+----------+--------------------------------+-----+---------+------------+
| 1 | 0 | Stuff for Sale | 1 | 1 | 1268488086 |
| 13 | 1 | Baby & Kids Stuff | 3 | 1 | 1268490153 |
| 121 | 13 | Baby Clothes | 1 | 1 | 1268492200 |
| 122 | 13 | Baby Toys | 2 | 1 | 1268492200 |
| 123 | 13 | Car Seats & Baby Carriers | 3 | 1 | 1268492201 |
| 124 | 13 | Nursery & Children's Furniture | 4 | 1 | 1268492201 |
| 125 | 13 | Prams & Strollers | 5 | 1 | 1268492201 |
| 126 | 13 | Other | 6 | 1 | 1268492201 |
+-------+----------+--------------------------------+-----+---------+------------+
When I run with a subselect:
mysql> select catid, (select catname from cats where catid=1) as toplevel, (select catname from cats where catid=13) as
parent, catname, pos from cats c where c.parentid=13;
I get this:
+-------+----------------+-------------------+--------------------------------+-----+
| catid | toplevel | parent | catname | pos |
+-------+----------------+-------------------+--------------------------------+-----+
| 121 | Stuff for Sale | Baby & Kids Stuff | Baby Clothes | 1 |
| 122 | Stuff for Sale | Baby & Kids Stuff | Baby Toys | 2 |
| 123 | Stuff for Sale | Baby & Kids Stuff | Car Seats & Baby Carriers | 3 |
| 124 | Stuff for Sale | Baby & Kids Stuff | Nursery & Children's Furniture | 4 |
| 125 | Stuff for Sale | Baby & Kids Stuff | Prams & Strollers | 5 |
| 126 | Stuff for Sale | Baby & Kids Stuff | Other | 6 |
+-------+----------------+-------------------+--------------------------------+-----+
6 rows in set (0.00 sec)
mysql>
How can I achieve the same result without using subselects to get the same result.