If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Help: Selecting from two tables: odd situation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-04, 16:32
mikeken mikeken is offline
Registered User
 
Join Date: Jul 2004
Posts: 6
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.
Reply With Quote
  #2 (permalink)  
Old 07-23-04, 19:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
left outer join
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-23-04, 20:57
mikeken mikeken is offline
Registered User
 
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?
Reply With Quote
  #4 (permalink)  
Old 07-23-04, 21:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
yeah, it's the same

some databases allow the OUTER keyword to be optional
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On