Reputation: 1485
I'm just getting the hang of JOINs in SQL (very powerful, could have made my code a lot more efficient if I'd looked them up earlier!), but am struggling with joining two or more tables with the same column name, then processing with PHP.
Here's the query that I've been trying, using aliases
SELECT *, TABLE1.ID AS t1_id, TABLE3.ID AS t3_id
FROM TABLE1, TABLE2, TABLE3
etc (with a left join)
Only table1
and table3
have the same ID column name, is there something wrong in this code? I'm getting the dreaded mysqli_error()
in PHP!
Any help greatly appreciated - can't seem to find the solution elsewhere when selecting everything from more than one table. Could specify each column name, but there would be over one hundred!
Upvotes: 0
Views: 795
Reputation: 649
SELECT
t1.ID AS t1_id,
t2.ID AS t2_id,
t3.ID AS t3_id
FROM
TABLE1 as t1
LEFT JOIN TABLE2 AS t2
LEFT JOIN TABLE3 AS t3
Upvotes: 4