Mr Chris Posted July 8, 2009 Share Posted July 8, 2009 Hello I have my query to select a distinct column item named product_grouping (which is an INT in the db) as well as the other columns id and price which are not distinct. SELECT DISTINCT product_grouping, id, price FROM tbl WHERE product_grouping !=3 ORDER BY rand( ) LIMIT 4 But it produces these results: product_grouping | id | price --------------------------------- 8 |5 | 9.99 1 |4 |9.99 2 |6 |9.99 1 |2 |9.99 But I ask for a distinct product grouping yet I get two 1 results returned? Quote Link to comment https://forums.phpfreaks.com/topic/165193-question-on-distinct/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 8, 2009 Share Posted July 8, 2009 The ALL, DISTINCT, and DISTINCTROW options specify whether duplicate rows should be returned. If none of these options are given, the default is ALL (all matching rows are returned). DISTINCT and DISTINCTROW are synonyms and specify removal of duplicate rows from the result set. DISTINCT operates on the rows in the results set, testing everything that is selected. You can use - GROUP BY product_grouping Quote Link to comment https://forums.phpfreaks.com/topic/165193-question-on-distinct/#findComment-871102 Share on other sites More sharing options...
fenway Posted July 8, 2009 Share Posted July 8, 2009 But then you'll get a random ID & price. Quote Link to comment https://forums.phpfreaks.com/topic/165193-question-on-distinct/#findComment-871159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.