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 > Subquery doesn't work, syntax is correct???

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-04, 20:23
phake123 phake123 is offline
Registered User
 
Join Date: Mar 2004
Posts: 15
Subquery doesn't work, syntax is correct???

I just installed Mysql 4.0.18

I tried to run ths sql statement

Select a.price, a.name
from rooms
where a.price = (Select max(price) from rooms);


I don't believe the syntax is wrong. Can anyone help me? I checked the data in the [Rooms] table which are all valid.

When I run:
Select max(price) from rooms;

It works, but when its in a subquery it doesn't.

I get this error:
Error 1064: You have an error in your SQL syntax. Check the manual that correspond to your MYSQL server version for the right syntax to use near 'Select max(price) from rooms' at line 3

Any help is greatly appreciated
Reply With Quote
  #2 (permalink)  
Old 04-03-04, 22:02
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
You can't use subqueries before version 4.1
Reply With Quote
  #3 (permalink)  
Old 04-04-04, 09:41
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
workaround:
PHP Code:
select t1.price
     
t1.name
  from rooms 
as t1
cross
  join rooms 
as t2
group
    by t1
.price
     
t1.name
having t1
.price max(t2.price
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 04-04-04, 16:01
aus aus is offline
Registered User
 
Join Date: Oct 2003
Location: Denver, Colorado
Posts: 137
Or, since HAVING is not optimized in MySQL and a CROSS JOIN could be expensive on a large table, you could do:
Code:
SELECT price, name FROM rooms
ORDER BY price DESC LIMIT 1;
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