SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    Houston, Texas, USA
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Converting an Oracle Query to MySQL

    I am stumped on how to convert this Oracle query into a MySQL equivalent.

    The version of MySQL we are using does not allow subqueries.

    Any suggestions on how we can convert this query?



    select a.id, a.location, a.price
    from
    prices_table a
    where
    a.location = 'HOUSTON'
    and a.id = (select max(id) from prices_table b
    where b.location = a.location)
    and a.price < 1.7176

  2. #2
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's called the max-concat trick. Try searching MySQL.com for the string group-wise maximum.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    there's also the self-join technique:
    Code:
    select a.id, a.location, a.price
      from prices_table a
    inner
      join prices_table b
        on a.location
         = b.location
     where a.location = 'HOUSTON'
       and a.price < 1.7176
    group
        by a.id, a.location, a.price
    having a.id = max(b.id)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    Houston, Texas, USA
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your replies! I will try those techniques.


Bookmarks

Posting Permissions

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