本文介绍了MySQL INNER JOIN别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道我如何在其中进行内部联接和别名值,以使它们不会彼此覆盖吗?如果您看到我的代码,看起来可能会更清楚:

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:

    SELECT  home, away, g.network, g.date_start
    FROM    game g
    INNER JOIN team t ON (
        (t.importid = g.home) as home
        OR
        (t.importid = g.away) as away
    )
    ORDER BY date_start DESC
    LIMIT 7

已解决(在下面的帮助之后,这是我的最终查询)

SOLVED (After the help below here is my final query)

    SELECT
        home.market AS home_market,
        away.market AS away_market,
        g.network,
        g.date_start

    FROM game AS g
    INNER JOIN team AS home ON (
        home.importid = g.home
    )
    INNER JOIN team AS away ON (
        away.importid = g.away
    )

    ORDER BY g.date_start DESC
    LIMIT 7

推荐答案

您需要加入两次:

SELECT home.*, away.*, g.network, g.date_start
FROM game AS g
INNER JOIN team AS home
  ON home.importid = g.home
INNER JOIN team AS away
  ON away.importid = g.away
ORDER BY g.date_start DESC
LIMIT 7

这篇关于MySQL INNER JOIN别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 12:17