views:

1319

answers:

2

i am running this query on mysql

 SELECT ID FROM (SELECT ID, msisdn FROM (SELECT * FROM TT2));

and it is giving this error:

Every derived table must have its own alias.

what is wrong ?

+3  A: 

I think it's asking you to do this:

SELECT ID FROM (SELECT ID, msisdn FROM (SELECT * FROM TT2) as myalias) as anotheralias;

But why would you write this query in the first place?

hometoast
the actual query is too long.. i have shortened it enough that people here have less time understanding it. the error on the short and long query was same.
silverkid
I understand now. I was also thinking it might have been generated by some code. It should still simplify as Paul and DMKing suggested.
hometoast
+5  A: 

Every derived table must indeed have an alias.

SELECT ID FROM (
    SELECT ID, msisdn FROM (
        SELECT * FROM TT2
    ) AS T
) AS T

In your case, the entire query could be replaced with:

SELECT ID FROM TT2
Paul