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,531
  • 2
  • 40
  • 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
  • 54,530
  • 11
  • 89
  • 103
1

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

:)

Neil Knight
  • 47,437
  • 25
  • 129
  • 188
JAiro
  • 5,914
  • 2
  • 22
  • 21