I want to use the SELECT DISTINCT
statement to filter the results of my result table. I'm trying to display the names of the products (ProductName
) that have unique discount percentages (DiscountPercent
). That way, it only shows products that have unique discount percentages.
My code is as follows:
select
p1.ProductName, p2.DiscountPercent
from
Products p1
right join
(select distinct DiscountPercent
from Products) p2 on p1.DiscountPercent = p2.DiscountPercent
order by
ProductName --I need to have it ordered by ProductName
This returns a table; however, the table still has duplicate information in the DiscountPercent
column. That's what I'm trying to get rid of.
Please keep in mind that I am new to SQL Server and coding in general. Any help would be greatly appreciated!
(I have searched for an answer to this multiple times, implementing solutions from other questions; however, their solutions always displayed my result table with only the ProductName
column.)