MySQL INNER JOIN Alias

前端 未结 2 1411
广开言路
广开言路 2020-12-28 13:34

Does anyone know how I can do an inner joins and alias values within so they won\'t overwrite each other? It might look more clear if you see my code:

    SE         


        
2条回答
  •  情歌与酒
    2020-12-28 14:25

    Use a seperate column to indicate the join condition

    SELECT  t.importid, 
            case 
                when t.importid = g.home 
                then 'home' 
                else 'away' 
            end as join_condition, 
            g.network, 
            g.date_start 
    FROM    game g
    INNER JOIN team t ON (t.importid = g.home OR t.importid = g.away)
    ORDER BY date_start DESC 
    LIMIT 7
    

提交回复
热议问题