Evan Evan - 3 months ago 12
SQL Question

Is this SQL query syntax correct?

SELECT DATEDIFF(dd, (SELECT date FROM player WHERE
date = (SELECT MAX(date) FROM player WHERE name = 'Deuslegio')
AND name = 'Deuslegio'), CURDATE())


Basically, all I am trying to do is get the latest row record's date of a certain player name
and getting the difference from today's date. But according to the phpMyAdmin on GoDaddy, I am getting this error:


Error: 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 ' CURDATE())' at line 1

Answer

You are using three parameters in your DATEDIFF function:

 1. dd 
 2. (SELECT DATE FROM player WHERE DATE = (SELECT MAX(DATE) FROM player WHERE NAME = 'Deuslegio')   AND NAME = 'Deuslegio')
 3. CURDATE()

You may only use two.

mySQL DATEDIFF()