Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    6

    Unanswered: Help: Selecting from two tables: odd situation

    Hi, I have two tables setup as shown below:

    Table name,"config"
    +-----------------+-----------------+
    | config_name | config_value |
    +-----------------+-----------------+
    | default_style | 1 |
    | *other names | *other values |
    +-----------------+-----------------+

    Table name,"styles"
    +-----------------+-----------------+
    | style_id | style_name |
    +-----------------+-----------------+
    | 1 | Purple Hue |
    | *other names | *other values |
    +-----------------+-----------------+


    Now, for my question:
    I need to select everything (*) from the config table
    and the 'style_name' from the styles table where style_id of the styles table is equal to the value of default_style of the config table.


    I got as far as this query
    "SELECT config.*, styles.style_name FROM `config`, `styles` WHERE config.default_style = styles.style_id LIMIT 1"

    But obviously that will not work.

    I know I can do this with two queries, but I am optimizing and I would like to reduce this down to 1 query, is this even possible to do with one query?

    Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    left outer join
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2004
    Posts
    6
    Is this the same as a left join? I have heard of left join, but never of a left outer join.

    Just an alias or what?

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yeah, it's the same

    some databases allow the OUTER keyword to be optional
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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