Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.