Click to See Complete Forum and Search --> : table alias not usable
dlgandalf
10-11-2007, 02:41 PM
Hi
I have got something in the likings of
select name from ([ long subquery]) AS subQTable where price = (
select max(price) from subQTable
)
why is this giving an error in mysql (newest stable 5.xx)
what's the use of giving the table an alias if i can't use it any where else
mattyblah
10-11-2007, 05:32 PM
i believe aliasing only helps when you are trying to reference columns, not the table itself. so if I had the following:
select columns from reallylongnamedtable inner join reallylongnamedothertable on reallylongnamedtable.for_key = reallylongnamedothertable.prim_key
it would be easier to write:
select columns from reallylongnamedtable a inner join reallylongnamedothertable b on a.for_key = b.prim_key
hope that makes sense.
dlgandalf
10-12-2007, 05:03 AM
but why MUST a alias be given when using a derived table? (the one in my topic start)
If I'd leave it out, mysql would give an error.
mattyblah
10-12-2007, 05:29 PM
not only must an alias be used but you also need to qualify each column in the subquery i believe (no count(*) or other aggregates without providing a column name). I'm not sure why a subquery needs to be aliased...