We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Need help using distinct in a select sql query

This is my query

SELECT DISTINCT brand, category FROM product WHERE subcategory = '$subcategory'

My problem is that i want the distinct to work on both brand and category, but it is only working on brand. How could i fix this?

3
Contributors
2
Replies
6 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
Jfunch
Light Poster
27 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You need to use 2 separate queries. Current query will give distinct combination of 2 colums

 SELECT DISTINCT  category FROM product WHERE subcategory = '$subcategory'

  SELECT DISTINCT brand FROM product WHERE subcategory = '$subcategory'
urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24
select b.brand, c.category
from 
(SELECT DISTINCT brand from product) b,
(SELECT DISTINCT category from product) c
smantscheff
Nearly a Posting Virtuoso
1,297 posts since Oct 2010
Reputation Points: 321
Solved Threads: 270
Skill Endorsements: 8

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0573 seconds using 2.64MB