Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2003
    Posts
    15

    Unanswered: A little more tricky scenario

    Tryng to return column values from different tables in one SQL call.

    Here is my scenario.

    Table Name: CUSTOMER
    ID | NAME
    --------------------------------
    1 | SIEBEL
    2 | IBM
    3 | AMCO

    Table Name: KEY
    ID | LOCATION
    --------------------------------
    1 | CALIFORNIA
    2 | TEXAS
    3 | IOWA

    Table Name: ATTRIBUTES
    ID | PHONE
    --------------------------------
    1 | (555)555-5555


    So as you can see an ID may or may not be present in the last two tables. ID in Customer table will always exist.

    I want to write a SQL query that would return a record set as follows when I pass it a valid ID:

    ID | LOCATION | PHONE
    --------------------------------
    1 | CALIFORNIA | (555)555-5555



    Thanks in advance, i wish i was good at SQL but im out of my element when it comes to queries.

    - L

  2. #2
    Join Date
    Oct 2003
    Location
    St.Louis,MO
    Posts
    120

    Re: A little more tricky scenario

    Originally posted by linkey
    Tryng to return column values from different tables in one SQL call.

    Here is my scenario.

    Table Name: CUSTOMER
    ID | NAME
    --------------------------------
    1 | SIEBEL
    2 | IBM
    3 | AMCO

    Table Name: KEY
    ID | LOCATION
    --------------------------------
    1 | CALIFORNIA
    2 | TEXAS
    3 | IOWA

    Table Name: ATTRIBUTES
    ID | PHONE
    --------------------------------
    1 | (555)555-5555


    So as you can see an ID may or may not be present in the last two tables. ID in Customer table will always exist.

    I want to write a SQL query that would return a record set as follows when I pass it a valid ID:

    ID | LOCATION | PHONE
    --------------------------------
    1 | CALIFORNIA | (555)555-5555



    Thanks in advance, i wish i was good at SQL but im out of my element when it comes to queries.

    - L
    Select c.id, k.location, a.phone
    from CUSTOMER c, KEY k, ATTRIBUTES a
    where c.id=k.id and
    k.id=a.id;

  3. #3
    Join Date
    Aug 2003
    Posts
    15
    Thanks tlael,
    But if I was passing in the initial CUSTOMER ID how would i incorporate that?
    or rather where would i insert c.ID='1' type of fragment?


    Thanks,

    - L

  4. #4
    Join Date
    Aug 2003
    Posts
    15
    Actually figured it out. Thanks for your help!!!!

  5. #5
    Join Date
    Jan 2004
    Location
    Santa Monica, CA
    Posts
    33
    select c.id, k.location, a.phone
    from CUSTOMER c, KEY k, ATTRIBUTES a
    where c.id = V_ID and
    c.id=k.id and
    k.id=a.id;

    V_ID is the parameter.....

Posting Permissions

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