Subquery in FROM must have an alias

I have this query that I wrote in PostgreSQL that returns an error:

[Err] ERROR:
LINE 3: FROM (SELECT DISTINCT (identifiant) AS made_only_recharge

This is the whole query:

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' ) 

I have a similar query in Oracle that works fine. The only change is where I have EXCEPT in Oracle, I replaced it with the MINUS keyword. I'm new to Postgres and don't know what he is asking for. What is the right way to handle this?

+67
sql oracle postgresql subquery
Feb 08 '13 at 6:50
source share
2 answers

add ALIAS to 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 
+92
Feb 08 '13 at 6:50
source share

You can also change to upgrade Postgresql to 10 instead of

0
Apr 18 '19 at 3:14
source share



All Articles