Jump to content

Question on DISTINCT


Mr Chris

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/165193-question-on-distinct/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/165193-question-on-distinct/#findComment-871102
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.