Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ambiguous column error when joining 2 tables which have the same column name

in my table A {ID, FID, Name , Age}
in my table B{ID, Job}

When I use

SELECT ID // I want to get the ID of table B //**error**//
FROM A TA JOIN B TB
ON TA.ID = TB.FID
ORDER BY TA.Name;

Error: ambiguous column name ID

Is there anyway to do that without having to rename the column name? (The Worst scenario)
Thank you

like image 840
Xitrum Avatar asked Dec 21 '22 10:12

Xitrum


1 Answers

SELECT TB.ID
FROM A TA JOIN B TB
ON TA.ID = TB.FID
ORDER BY TA.Name;

Use the full name (table name and column name seperated by a dot) to specifically select a column.

Your query doesn't fit your described table structure, I guess you swapped table A with table B.

like image 170
Jacob Avatar answered May 14 '23 06:05

Jacob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!