I have a table of customer order data that looks like this:
As you can see, there's a row for billing and a row for shipping for EACH order. parent_id
is what tethers these rows together in to one order. What I need to do is write a query that finds all cases where there's a last_name
OR zip_code
mismatch between two rows with the same parent_id
(i.e. the billing and shipping info is different). I'm at something of a loss for how to construct this query because this doesn't work for pretty obvious reasons:
SELECT *
FROM order_addresses
WHERE parent_id = parent_id
AND last_name <> last_name
What I think I need to really do is find all cases where parent_id
matches FIRST and then step down and see whether zip_code
and last_name
also match and display all results where they do not. I don't know how to do that. Any pointers would be great, thank you!