Nitin Garg
Nitin Garg

Reputation: 2079

sql query error

With the following query:

SELECT SeatPref FROM (SELECT SeatPref, COUNT(CustID) AS seat_count FROM Booking 
    GROUP BY SeatPref) WHERE seat_count = max(seat_count)

I am getting the following error:

Every derived table must have its own alias.

Upvotes: 0

Views: 61

Answers (2)

JAiro
JAiro

Reputation: 5999

You Should add an alias to the subquery (SELECT SeatPref, COUNT(CustID) AS seat_count FROM Booking GROUP BY SeatPref).

:)

Upvotes: 1

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55489

You are missing table alias -

SELECT t1.SeatPref 
FROM (SELECT SeatPref, COUNT(CustID) AS seat_count 
      FROM `Booking` 
      GROUP BY SeatPref)  t1
WHERE t1.seat_count = max(t1.seat_count) 

Upvotes: 6

Related Questions