Is this second join correct ?
Can some one please advise if this second join is correct. It does work, and I've checked a number of rows, but I just need to be sure I have done the second join correctly (the first join was already being used and is correct).
Now, the join is currently:
and we needed to retrieve the "state", which is in fact the "zone name", some data from the ZONES table as follows:
select c.*, adb.* from customers as c left join address_book as adb on c.customers_id = adb.customers_id ORDER BY customers_lastname, customers_firstname
zone_id zone_country_id zone_code zone_name
1 223 AL Alabama
2 223 AK Alaska
3 223 AS American Samoa
4 223 AZ Arizona
5 223 AR Arkansas
6 223 AF Armed Forces Africa
The modified SQL query to join the ZONES table is:
Does that look correct ?
select c.*, adb.*, z.* from customers as c left join address_book as adb on c.customers_id = adb.customers_id left join zones as z ON (adb.entry_zone_id = z.zone_id AND adb.entry_country_id = z.zone_country_id) ORDER BY customers_lastname, customers_firstname