Select products with users
Posted
by
Ploppe
on Stack Overflow
See other posts from Stack Overflow
or by Ploppe
Published on 2012-10-18T16:57:54Z
Indexed on
2012/10/18
17:00 UTC
Read the original article
Hit count: 123
I have not worked with SQL for quite a long time, and I need some help for a basic query. I have the three following tables:
users (id, name)
products (id, name)
owners (userid, productid, date)
One product can be sold by user A to user B and then back to A.
Now, I want the list of all products currently owned by every single user with the date of transaction.
Currently, my query is this one, but I'm stuck with old data (first association of one product to one user, and not the newest one):
SELECT users.name, products.name, date
FROM products
JOIN owners ON products.id = owners.id
JOIN users ON owners.id = user.id
GROUP BY product.id
Do you have some hints?
Thanks
© Stack Overflow or respective owner