Reputation: 5
I have table1 and table2 in a Mysql database.
Each table has a field with the same name, let's say "id".
I need a query where I can get the "id" field value of both tables. I tried this:
SELECT
table1.id,
table2.id
FROM...
But I got an error message:
Unknown column 'table1.id' in 'field list'
Upvotes: 0
Views: 1383
Reputation: 263723
you need to add ALIAS
on the columns
SELECT
table1.id AS table1_ID, -- keyword AS is optional
table2.id AS table2_ID
FROM...
and call their alias (for example) $row["table1_ID"]
in PHP .
on more thing Unknown column 'table1.id' in 'field list'
results from columns that are unable to be find by the server on your join statements.
follow-up question, can you post the whole query?
Upvotes: 2