I have 4 tables and this query
SELECT tag.id, title
FROM tag
LEFT JOIN tag_map ON ( tag.id = tag_map.tag_id )
LEFT JOIN post ON ( post.id = post_id )
LEFT JOIN game ON ( game.id = post_id )
LEFT JOIN video ON ( video.id = post_id )
WHERE tag_slug = "blizzard"
ORDER BY tag_map.post_type
The problem in this query is that the 3 tables on the left join statement all have a title column. Because of this I’m getting the “Column ‘title’ in field list is ambiguous” error.
How can I handle this so that the query shows the related title field for each row..
Based on the additional information supplied in a comment to another response, it appears that the a DIFFERENT title field needs to be selected depending on the post_type, with post_types corresponding to the post, game, and video tables.
I’ll assume that post_type is a one character text column.
You can do that in two ways, with LEFT JOIN or UNION.
However, a UNION solution might be clearer:
(Note, I simplified the answers slightly because it’s not clear to me the relation between tag and tag_map, you might need to introduce both tables into the SELECTS).