Skip to content
Advertisement

How avoid ambiguousness when joining tables with a where statement?

i have a query such as

since both tables have id and booking_id i am getting : column reference "id" is ambiguous

Advertisement

Answer

Qualify the column references — all of them.

To facilitate this, use table alias that are abbreviations of the table names. Something like this:

(Note: I don’t know if you want b.id = 1 or a.id = 1, but the latter condition should be in the ON clause for a LEFT JOIN.)

I would also advise you to list out the columns in the SELECT — you have duplicate names so you want to be careful there too.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement