Reputation: 4189
Why do I get this error? I need to select both these as distinct, but Im I coding it wrong here?
ERROR: syntax error at or near "DISTINCT"
SELECT DISTINCT(mfin_score), DISTINCT(empirica_score ) from account_details
Upvotes: 5
Views: 23957
Reputation: 8058
For others like me who got this error - DISTINCT
needs to come right after the SELECT
(before any columns). And will deduplicate the combination of all columns supplied.
Upvotes: 2
Reputation: 466
If you want the distinct couples of mfin and empirica:
select distinct mfin_score, empirica_score
from account_details
If you want the distinct mfin and the distinct empirica you have to do something different:
select distinct 'MFIN' As code, mfin_score
from account_details
union all
select distinct 'EMP' As code, empirica_score
from account_details
you may have to check the syntax of postgresql for Alias, not sure if it's the same as oracle
Upvotes: 2
Reputation: 2972
The right syntax for DISTINCT keyword is
SELECT DISTINCT column_name,column_name
FROM table_name;
So you can write
SELECT DISTINCT mfin_score, empirica_score from account_details
instead of
SELECT DISTINCT(mfin_score), DISTINCT(empirica_score ) from account_details
Upvotes: 2
Reputation: 8881
DISTINCT
is a KEYWORD
not a FUNCTION
hence it will be better if you try
SELECT DISTINCT mfin_score, empirica_score from account_details
Upvotes: 4
Reputation: 103
just use this
SELECT DISTINCT mfin_score, empirica_score from account_details
Upvotes: 2
Reputation: 181340
You can do:
select distinct mfin_score, empirica_score
from account_details
Keyword distinct
is not a function. It's a keyword to state that you want only distinct
tuples on your result set.
Upvotes: 5