Home >Database >Mysql Tutorial >Why Does My PostgreSQL Subquery Need an Alias in the FROM Clause?
Subquery Aliasing in PostgreSQL
When facing the error message "[Err] ERROR: LINE 3: FROM (SELECT DISTINCT (identifiant) AS made_only_recharge", it indicates that a subquery in the FROM clause is missing an alias.
In the given query, the subquery is used to calculate the number of distinct identifiers that appear in the cdr_data table only for the CALLEDNUMBER value of '0130'. However, the subquery lacks an alias, which PostgreSQL requires for subqueries appearing in the FROM clause.
To resolve this issue, add an alias to the subquery, as shown below:
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 -- ALIAS ADDED
The above is the detailed content of Why Does My PostgreSQL Subquery Need an Alias in the FROM Clause?. For more information, please follow other related articles on the PHP Chinese website!