Can I do this in one query?
Posted: Fri Jul 20, 2007 1:58 am
Hello,
I have a query that pulls basic info:
select id,name, title, phone from contacts limit 30;
but for each row I want to display an unknown number of tags connected to the contact record.
select * from tags where contact.id = tags.contact_id;
The output I'm trying to get is:
id, name, title, phone
tag1, tag2, tag3, tag4, tag5, .....
id,name,title,phone
tag1, tag2, tag3, tag4, tag5, .....
I can get to the results above using seperate queries for each row to lookup the tags BUT this is slow
and I have a feeling I can do it in my initial query. Can I append an unknown number of items with a join clause?
Thanks!
I have a query that pulls basic info:
select id,name, title, phone from contacts limit 30;
but for each row I want to display an unknown number of tags connected to the contact record.
select * from tags where contact.id = tags.contact_id;
The output I'm trying to get is:
id, name, title, phone
tag1, tag2, tag3, tag4, tag5, .....
id,name,title,phone
tag1, tag2, tag3, tag4, tag5, .....
I can get to the results above using seperate queries for each row to lookup the tags BUT this is slow
and I have a feeling I can do it in my initial query. Can I append an unknown number of items with a join clause?
Thanks!