Thread: work on rows
Hello,
I have a problem with a sql query.I have two tables : the first contains categories and the second subcategories.
What kind of select may I use to get something like Yahoo! categories ( each "main" category gets *at most* three sub-categories..
Thanks
Regards,
Rachel
Author: Rachel Coin <rachel@derniere-minute.org> I have a problem with a sql query.I have two tables : the first contains categories and the second subcategories. What kind of select may I use to get something like Yahoo! categories ( each "main" category gets *at most* three sub-categories.. Do you mean something like the following? (PS - please don't post HTML to mailing lists) richardh=> select * from cats;c ---AB (2 rows) richardh=> select * from subcats;c | s ---+----A | a1A | a2A | a3A | a4 (4 rows) richardh=> select cats.c,subcats.s from cats,subcats where cats.c=subcats.c;c | s ---+----A | a1A | a2A | a3A | a4 (4 rows) richardh=> select cats.c,subcats.s from cats,subcats where cats.c=subcats.c and subcats.s in (select s from subcats where subcats.c=cats.c limit 2);c | s ---+----A | a1A | a2 (2rows) - Richard Huxton