Overcoming ambiguous field error in SQL query

后端 未结 3 1945
野趣味
野趣味 2021-01-22 22:37

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         


        
3条回答
  •  轮回少年
    2021-01-22 23:23

    You need to specify which table you want title to come from. Taking a guess that title will be in game you would need to specify game.title.

    If I were you I'd start looking into splitting this down a bit using temporary tables. Although theres nothing wrong with 4 joins it does tend to start getting confusing.

    Example temp table:

    CREATE TABLE #Yaks (
    YakID int,
    YakName char(30) )
    

    In your scenario you would create a temp table and then fill it with an INSERT and UPDATE based on individual joins so at the end all you have to do is SELECT * FROM @temptable

提交回复
热议问题