-1

I'm using dbForge mySQL version 5.7. I have the following query:

SELECT product, location, last_updated
FROM (
    SELECT 
        product, 
        location, 
        last_updated,
        RANK() OVER (PARTITION BY product ORDER BY last_updated DESC) as rn
    FROM warehouse
)temp
WHERE temp.rn = 1;

I'm trying to get the last location of a product in the warehouse; a product can have many different locations at different times. I keep getting a syntax error, but I do not see what I'm doing wrong. Any thoughts?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
dkro23
  • 17
  • 4
  • 1
    Window functions were added in MySQL 8.0. You can't use them in 5.7. – Barmar Aug 14 '23 at 19:07
  • See https://stackoverflow.com/questions/1313120/retrieving-the-last-record-in-each-group-mysql?rq=1 for how to do this without window functions. – Barmar Aug 14 '23 at 19:08
  • "I do not see what I'm doing wrong". What you are doing wrong is you are using an ancient version of MySQL that do not have window functions. – Eric Aug 14 '23 at 20:43

0 Answers0