Jump to content


Select Distinct

  • Please log in to reply
1 reply to this topic

#1 wipeskim

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 July 2006 - 04:58 PM


I am doing a script with php and mysql wich i want to list the orders details such as session_id, date, username and id.

To do this i used select distinct session_id from orders

cause i have 2 orders with the same session_id but i also want to list the username, date and id.

Since i used to distinct only the session_id it will only print on the screen the session id's.

I tryed "select Distinct session_id, username, date,id from orders" but in this case since some fields has diferent values even having the same session_id it will list all the results on the table.

What i would like to do is like "select * from orders distinct session_id" , this query doesn't work but just to give an idea.

Is there anyway of using the select statement to select all the fields and distinguish the session_id so that i can avoid duplicated session id's on the results?

If someone can help me i appreciate

Many thanks to all

#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 23 July 2006 - 06:30 PM

You're correct that DISTINCT only eliminates duplicates rows, where all field values match.  You can easily run a query to limit to unique session_ids, but what will that mean for the username, etc?  Might they be different across similar session_ids?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users