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 > where clause that uses result of another query?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-06, 18:12
Superfly1611 Superfly1611 is offline
Registered User
 
Join Date: Apr 2004
Location: UK
Posts: 40
where clause that uses result of another query?

Hi,

I'm looking to refine ways i've written my current application to make it more efficient.
Is it possible to write a query who's WHERE parameter is the result of another query without using a procedure/function?
Use the classic Product details table as an example

My query currently looks like
SELECT productID, productDescription, productPrice from tblProducts where productPrice >= (Select productPrice from tblProducts where productID = 7)

This is probably a bad example but the underlined part of that query show what i'm trying to achieve.
Is it possible to use another query as part of the WHERE clause?
At the moment i'm getting syntax errors.

Many Thanks
Reply With Quote
  #2 (permalink)  
Old 04-20-06, 18:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yes it is possible, we do this all the time
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-21-06, 04:30
Superfly1611 Superfly1611 is offline
Registered User
 
Join Date: Apr 2004
Location: UK
Posts: 40
So is the syntax I used above correct?
Reply With Quote
  #4 (permalink)  
Old 04-21-06, 04:56
Superfly1611 Superfly1611 is offline
Registered User
 
Join Date: Apr 2004
Location: UK
Posts: 40
nvm - according to this article I wouldn't be able to alter the table in my query anyway (I was hoping to use this to write an UPDATE query) because i'd be using a subquery that looked up the same table I was trying to update.
Reply With Quote
  #5 (permalink)  
Old 04-21-06, 05:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by Superfly1611
So is the syntax I used above correct?
yep, it is
__________________
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