Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subquery in FROM must have an alias

People also ask

Can you alias a subquery?

We can also alias a subquery as if it were a table or view. As a result, we can then use the subquery reference in our SELECT statement.

Can subquery be used in FROM clause?

The FROM clause is the only context in which a subquery can specify the ORDER BY clause.

Which clause is not allowed in subquery?

Subqueries cannot manipulate their results internally, that is, a subquery cannot include the order by clause, the compute clause, or the into keyword. Correlated (repeating) subqueries are not allowed in the select clause of an updatable cursor defined by declare cursor. There is a limit of 50 nesting levels.

Which clause is mandatory in subquery?

"SELECT" clause is mandatorily used in a sub-query .


Add an ALIAS onto the subquery,

SELECT  COUNT(made_only_recharge) AS made_only_recharge
FROM    
    (
        SELECT DISTINCT (identifiant) AS made_only_recharge
        FROM cdr_data
        WHERE CALLEDNUMBER = '0130'
        EXCEPT
        SELECT DISTINCT (identifiant) AS made_only_recharge
        FROM cdr_data
        WHERE CALLEDNUMBER != '0130'
    ) AS derivedTable                           -- <<== HERE