MySQL Forums
Forum List  »  InnoDB

Joining Tags Tables and Related Rows
Posted by: John Giotta
Date: March 12, 2009 11:39AM

I have a tags table, a cross reference table, and then a primary table.
Selecting from the primary and joining the tags is no problem

SELECT primary_tbl.*, GROUP_CONCAT(DISTINCT tags_tbl.text) AS tags
FROM primary_tbl
LEFT JOIN xref_tbl ON xref_tbl.prime_id = primary_tbl.id
LEFT JOIN tags_tbl ON tags_tbl.id = xref_tbl.tag_id

But what I'm now trying to do is a SELECT a row from the primary table plus any other row that matches the tag text.

So if rowA had a tag of 'foobar' I want all other rows with the same tag.

Now obviously I could just separate the statements in my code, but I want to shoot for a single SQL-transaction.

Any advise?

Options: ReplyQuote


Subject
Views
Written By
Posted
Joining Tags Tables and Related Rows
3146
March 12, 2009 11:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.