Reputation: 1501
I have the following tables:
+--------+ +-------+ +----------+ +-------+
| blogs | | users | | blogtags | | tags |
+--------+ +-------+ +----------+ +-------+
| bid | | uid | | bid | | tid |
| uid | | name | | tid | | tag |
| title | +-------+ +----------+ +-------+
+--------+
Unfortunately I have a restriction whereby my MySQL server is separate to my web server. As such I want to minimise database calls.
I want to get a result like this:
bid | title | users.name | tag1 tag2 tag3 |
With the tags concatenated into one string.
I guess first question - is this even possible. Then could the kind SO community give me some guidance on how to do this.
I have been working all day and my brain is spinning even trying to work this out. I know I'm going to need some joins, a group-concant and probably a sub query but getting lost thinking about it. Thanks in advance
Upvotes: 0
Views: 55
Reputation: 2588
select bid, title, users.name, group_concat(tags.tag)
from blogs inner join users on blogs.uid=users.uid
inner join blogtags on blogs.bid=blogtags.bid
inner join tags on tabs.tif=blogtags.bid
group by bid, title, users.name
Upvotes: 1