Try to search your question here, if you can't find : Ask Any Question Now ?

Using DISTINCT to find the unique values of one column while displaying multiple colums

HomeCategory: stackoverflowUsing DISTINCT to find the unique values of one column while displaying multiple colums
Avatarwillson asked 4 months ago

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

1 Answers
Best Answer
AvatarMatthias answered 4 months ago
Your Answer

1 + 10 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com