Home > Software design >  Column in field list is ambiguous despite I have correct table names
Column in field list is ambiguous despite I have correct table names

Time:04-10

Here's the code, in theory this should work, right? But when I run this, the error comes up

"#1052 - Column 'spotID' in field list is ambiguous"

SELECT start, end, spotID FROM bookings
    INNER JOIN glampingspot ON (bookings.spotID = glampingspot.spotID)
    WHERE glampingspot.venueID = 1 
    AND glampingspot.maxPeople >= 3

And yes I am 1000% sure that the names of the tables are "bookings" and "glampingspot", and they have the same key "spotID"

CodePudding user response:

SELECT start, end, bookings.spotID FROM bookings
    INNER JOIN glampingspot ON (bookings.spotID = glampingspot.spotID)
    WHERE glampingspot.venueID = 1 
    AND glampingspot.maxPeople >= 3

It is always a good practice to resolve the scope of columns so that it is clear that which column comes from which table in the output.

  • Related