MySQL Forums
Forum List  »  Newbie

Why is this select statement pulling duplicates?
Posted by: Phil Nauta
Date: June 10, 2015 02:58PM

Hi, my mysql skills have hit a wall! Let's say a customer places an order with:
-Order id 101, for product with sku ABC, and their phone number is 555-555-5555.

Then they place an order with:
-Order id 202, for a product with sku DEF, and their phone number is 444-444-4444.

I want the following select statement to pull all records for orders of sku ABC. But it ends up pulling both of the above orders when a customer uses a different phone number on the two orders as in the above example, even when the second order has a different id and sku. Here's my select statement:

select distinct
orders.order_id, items.sku, customer.phone
from orders
join items on orders.order_id = items.order_id
join user on orders.user_id = customer.user_id
where items.sku='ABC'

And here's the result:
101, ABC, 555-555-5555
101, ABC, 444-444-4444

It must be a mistake in how I'm joining the tables together. Any thoughts? Thanks so much for your help! Phil

Options: ReplyQuote


Subject
Written By
Posted
Why is this select statement pulling duplicates?
June 10, 2015 02:58PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.