Jump to content

Select only one occurence


Ninjakreborn

Recommended Posts

This is driving me crazy. I have a table that has a lot of data in it. I have a field called Order ID that has multiple occurrences of each order ID.  I need to be able to get 1 record with Each order ID. I basically tried

using distinct..and it's still returning multiple occurrences of each order ID.

 

$result = mysql_query("SELECT DISTINCT order_id FROM jp_transaction_history WHERE last_name LIKE '%" . $last_name . "%' AND transaction_type = 'ss'");

 

ALL I want to do is get 1 record for every Order ID that is found..not duplicate order ID's.  Any advice, is appreciated.

Link to comment
Share on other sites

DISTINCT removes duplicate rows from the result set. Since the product_sku is probably different in each row, the the rows are all different and there's nothing for distinct to remove. If all you are trying to get is a list of distinct order_id's, why are you selecting other columns?

 

Use GROUP BY order_id to consolidate all rows having the same order_id into one row in the result set.

Link to comment
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.