What is the error “Every derived table must have its own alias” in MySQL?

后端 未结 4 1599
小鲜肉
小鲜肉 2020-11-21 09:07

I am running this query on MySQL

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

and it is giving this

4条回答
  •  长发绾君心
    2020-11-21 09:37

    Every derived table (AKA sub-query) must indeed have an alias. I.e. each query in brackets must be given an alias (AS whatever), which can the be used to refer to it in the rest of the outer query.

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

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

    SELECT ID FROM TT2
    

提交回复
热议问题