-1

I want to get all specific scores from users whose tablenames are stored in a list of users, something like this:

SELECT Score
from (SELECT tablenameOfUser FROM `Users`)
WHERE X='something'
  AND Y='somethingElse'
ORDER BY Score

I get the error:

1248 - Every derived table must have its own alias

jarlh
  • 42,561
  • 8
  • 45
  • 63
Mark
  • 103
  • 1
  • 9
  • Which dbms? (Seems to be ANSI SQL compliant... Except the single quotes for delimited identifiers...) – jarlh May 04 '15 at 12:18
  • I am using phpMyAdmin – Mark May 04 '15 at 12:21
  • possible duplicate of [every derived table must have its own alias](http://stackoverflow.com/questions/1888779/every-derived-table-must-have-its-own-alias) – AdamMc331 May 04 '15 at 13:09

1 Answers1

2

The error message says it all. You need an alias on your derived table.

SELECT Score
from (SELECT tablenameOfUser FROM `Users`)
WHERE X='something'
  AND Y='somethingElse'
ORDER BY Score

Should be:

SELECT Score
from (SELECT tablenameOfUser FROM `Users`) yourAlias
WHERE X='something'
  AND Y='somethingElse'
ORDER BY Score

Your subquery only has the tablenameOfUser column, so Score, X, and Y, will not be available and your query will still fail.

Mark Leiber
  • 3,118
  • 2
  • 13
  • 22