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 > Database Server Software > MySQL > Help, 2 table sql query.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-04, 16:08
mikeken mikeken is offline
Registered User
 
Join Date: Jul 2004
Posts: 6
Help, 2 table sql query.

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, 16:30
mikeken mikeken is offline
Registered User
 
Join Date: Jul 2004
Posts: 6
Sorry, I just realize I put this in the wrong forum, I will put it in the sql forum.
Reply With Quote
  #3 (permalink)  
Old 07-23-04, 17:33
deepblues deepblues is offline
Registered User
 
Join Date: Jun 2004
Posts: 2
Re: Help, 2 table sql query.

Try using left outer join.
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