php - UNION SELECT tables with inner join and GET values with "ALIAS" -
so have 2 tables, matches , teams, want values match , inner join "teams" names of both teams , add them php array later on (getting in 1 sql)
matches - idmatch - idlocalteam - idvisitorteam - time - half - stopped teams - idteam - name
what have is
$query = "select * `matches` inner join `teams` on `matches`.idlocalteam = `teams`.idteam union select * `matches` inner join `teams` on `matches`.idvisitorteam = `teams`.idteam order idmatch desc;";
if me great! alot
wouldn't easier use inner join twice? it's quicker way of doing joins anyway.
select * `matches` m inner join `teams` t1 on m.idlocalteam = t1.idteam inner join `teams` t2 on m.idvisitorteam = t2.idteam order m.idmatch desc;
also start using aliases instead of table names identify fields in query, sql smaller.
Comments
Post a Comment