difficulty with distinct parameter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bulgin
Forum Commoner
Posts: 29
Joined: Wed Feb 11, 2009 8:47 pm

difficulty with distinct parameter

Post by bulgin »

I have the following bit of code:

Code: Select all

SELECT distinct request_uri , sent_or_not_sent, id FROM web3_access_log where sent_or_not_sent = '0'
and the result set are 4 when I had hoped it would be just 1.

There are 4 records with the same request_uri but I only want returned 1 instance of that. In the above code the id's are all different and I'm sure that is why 4 rows are returned and not 1.

What would I do to make sure only the first occurrence of the request_uri is returned along with those other fields?

Much confused.

Thanks in advance.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: difficulty with distinct parameter

Post by Mark Baker »

DISTINCT applies across all the columns that you want returned, not just the first column in your select list; otherwise SQL can't know which values to return for the other columns.
Which of the four returned results do you actually want?
bulgin
Forum Commoner
Posts: 29
Joined: Wed Feb 11, 2009 8:47 pm

Re: difficulty with distinct parameter

Post by bulgin »

Mark Baker wrote:DISTINCT applies across all the columns that you want returned, not just the first column in your select list; otherwise SQL can't know which values to return for the other columns.
Which of the four returned results do you actually want?
Thank you. I thought that was my problem. I want distinct results for request_uri
Post Reply