I can’t think it over. I have this query:
SELECT
p.person_id,
p.first_nm,
p.last_nm,
pu.purchase_dt,
pr.sku,
pr.description,
a.address_type_id,
a.city_cd,
a.state_cd,
a.postal_cd
FROM
person p
INNER JOIN address a ON p.person_id = a.person_id
INNER JOIN purchase pu ON pu.person_id = p.person_id
INNER JOIN product pr ON pr.product_id = pu.product_id
Simple enough - I just need to get information for the customers we sent. However, due to the addressType table
AddressType
address_type_id address_type_desc
------------------------------------
1 Home
2 Shipping
some clients have multiple addresses in the address table, creating non-identical duplicate entries like this.
1,Smith, John, 12/01/2009, A12345, Purple Widget, 1, Anywhere, CA, 12345
1,Smith, John, 12/01/2009, A12345, Purple Widget, 2, Somewhere, ID, 54321
I want the request to return only one row / person and return the home address, if it is available otherwise, it returns the delivery address.
It seems simple enough, and maybe it's just my cold, but it makes me scratch my head a little.