Can someone verify if my query is producing the intended results that I am hoping for?
I am using PostgreSQL.
SELECT sold_at
, quantity
, returned_at
, name
, price
FROM sales
LEFT JOIN returns
ON sales.order_id=returns.order_id
JOIN products
ON sales.product_id=products.product_id
WHERE name LIKE '%sock%'
ORDER by sold_at ASC
sold_at | quantity | returned_at | name | price
2015-06-01 | 8 | |socks-toeless | 15
2015-06-01 | 7 | 2015-06-08| socks-flat | 15
My goal is for the output to include all sock purchases from the sales table (regardless of whether or not it was returned), and have a column that shows whether the sock order was returned that is populated with a date if it was returned and is blank if the item was not returned.
The name of the product (i.e., 'sock') comes from the product table.