Page 1 of 1

difficulty with distinct parameter

Posted: Sun Mar 01, 2009 5:12 pm
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.

Re: difficulty with distinct parameter

Posted: Sun Mar 01, 2009 5:56 pm
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?

Re: difficulty with distinct parameter

Posted: Sun Mar 01, 2009 6:01 pm
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