SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    595
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is this second join correct ?

    Hi,

    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:

    Code:
    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
    and we needed to retrieve the "state", which is in fact the "zone name", some data from the ZONES table as follows:

    ===========
    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:

    Code:
    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
    Does that look correct ?

    Thanks,

    Peter

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2003
    Location
    Melbourne, Australia
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't want to be rude, but if it works
    what are you asking? performance, syntax?

  3. #3
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    595
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by dtra
    don't want to be rude, but if it works what are you asking? performance, syntax?
    Lack of confidence in my abilities.

    Seriously, I used to do a lot of this stuff years ago, but am 'rusty' , and just need some guru to tell me it is the correct way to do it.

    Peter


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •