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
SQL aliases are custom names that you can give to the columns and tables you include in your queries. Aliases are very useful, as they can greatly improve the readability and maintainability of your query.
No, you cannot do that. The alias is not bound until later in the processing. You can use "Nombre" in an ORDER BY, but not in a WHERE clause and certainly not in a JOIN clause.
Difference between JOIN and INNER JOINJOIN returns all rows from tables where the key record of one table is equal to the key records of another table. The INNER JOIN selects all rows from both participating tables as long as there is a match between the columns.
You'll need to join twice:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With