Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Posts
    1

    Thumbs down Unanswered: 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 )

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    mysql does not support subqueries until version 4.1

    you can use this:

    SELECT hit_date FROM hits ORDER BY id LIMIT 1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •