I have a customer table and an address table. Each customer can have multiple entries in the address table, but only one of those entries can be marked as ‘primary’. I’ve put together the query to pull up the customer and their primary address as follows:
SELECT * FROM customers LEFT JOIN addresses
ON customers.cust_id = addresses.cust_id
WHERE customers.status = 1 AND addresses.primary = 1
I’ve found a flaw in that if the customer has not yet added an address to their account, they will not appear because there is no ‘primary’ address.
What’s the best way to work around this?
1 Answer