0

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.

YasirA
  • 9,433
  • 2
  • 38
  • 61
Nitin Garg
  • 2,069
  • 6
  • 25
  • 50
  • 1
    Have you looked at this? http://stackoverflow.com/questions/1888779/every-derived-table-must-have-its-own-alias – RQDQ Feb 17 '11 at 14:08

2 Answers2

6

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) 
Sachin Shanbhag
  • 52,879
  • 11
  • 86
  • 103
1

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

:)

Neil Knight
  • 45,890
  • 23
  • 126
  • 186
JAiro
  • 5,692
  • 2
  • 20
  • 21