SQLNewbee
SQLNewbee

Reputation: 1

SELECT DISTINCT WHILE JOINING TABLES

I'm new to SQL. I would like to ask some help. How can I select only distinct values from a joined table?

    SELECT fc.Indv_Sys_Id, DISTINCT(fc.Dt_Sys_Id)
    FROM MiniHPDM..Fact_Claims AS fc
    INNER JOIN MiniHPDM..Dim_Date AS d on fc.Dt_Sys_Id = d.Dt_Sys_Id

Any help would be greatly appreciated.

Thanks in Advance!

Upvotes: 0

Views: 943

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269603

If you want distinct values, then use SELECT DISTINCT:

SELECT DISTINCT fc.Indv_Sys_Id, fc.Dt_Sys_Id
FROM MiniHPDM..Fact_Claims fc INNER JOIN
     MiniHPDM..Dim_Date d 
     ON fc.Dt_Sys_Id = d.Dt_Sys_Id;

DISTINCT is not a function. It is a keyword, used in this case with SELECT.

Given that the join should succeed, I imagine that this returns the same results:

SELECT DISTINCT fc.Indv_Sys_Id, fc.Dt_Sys_Id
FROM MiniHPDM..Fact_Claims fc
WHERE fc.Dt_Sys_Id IS NOT NULL;

Upvotes: 3

Related Questions