I have a simple query that tries to select a distinct Country column from the Customer table, but it is returning duplicate values.
Country City PostalCode CustomerName ContactName
USA Lander 82520 Split Rail Beer & Ale Art Braunschweiger
Germany Leipzig 4179 Morgenstern Gesundkost Alexander Feuer
France Lille 59000 Folies gourmandes Martine Rancé
Portugal Lisboa 1675 Furia Bacalhau e Lino Rodriguez
Portugal Lisboa 1756 Princesa Isabel Vinhoss Isabel de Castro
UK London WA11DP Around the Horn Thomas Hardy
UK London EC25NT B's Beverages Victoria Ashworth
UK London WX16LT Consolidated Holdings Elizabeth Brown
UK London WX36FW Eastern Connection Ann Devon
I want to get only distinct country name and it doesn't matter other column result. So I'm running below SQL code but it keep giving me some duplicate values.
with all_data as (SELECT distinct Country , City, PostalCode, CustomerName,ContactName FROM Customers),
distinct_country as (
SELECT distinct Country FROM Customers
),
distinct_values as (
SELECT t.Country , a.City, a.PostalCode, a.CustomerName,a.ContactName
FROM distinct_country t
left join
all_data a
on t.Country = a.Country
)
select * from distinct_values
I'm looking like the below result. (the distinct country name and it doesn't matter other column result)
Country City PostalCode CustomerName ContactName
USA Lander 82520 Split Rail Beer & Ale Art Braunschweiger
Germany Leipzig 4179 Morgenstern Gesundkost Alexander Feuer
France Lille 59000 Folies gourmandes Martine Rancé
Portugal Lisboa 1675 Furia Bacalhau e Lino Rodriguez
UK London WA11DP Around the Horn Thomas Hardy
How can I do that? Thanks in advance!