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 > Select within a select statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-04, 05:18
Bertman Bertman is offline
Registered User
 
Join Date: Jul 2004
Posts: 1
Thumbs down Select within a select statement

Hello,

Select within a select statement is what i'm using in MS Access, but it doesn't seems te work in MySQL.

Database look
Table Hits
hit_id (autonumber)
hit_date
hit_ip

I just want to have the hit_date of the lowest hit_id, in access the query normaly looks like this:
SELECT hit_date FROM hits WHERE hit_id = (SELECT min(hit_id) as minid FROM hits)

In MySQL I get a error:
[Server01] ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT min(hit_id) as minid FROM hits)' at line 1

When I use the statements apart, he works fine. So like this:
SELECT hit_date FROM hits WHERE hit_id = 1
SELECT min(hit_id) as minid FROM hits

Does anyone has a sollution ?
Google search give me this, but is doens't work.(http://www.squeekmachine.co.uk/code.php?s=5&c=17 )
Reply With Quote
  #2 (permalink)  
Old 07-23-04, 06:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
mysql does not support subqueries until version 4.1

you can use this:

SELECT hit_date FROM hits ORDER BY id LIMIT 1
__________________
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