I have a table called downloads
which has records of files which have been downloaded from various URL's. There is a column downloads.created
which is a DATETIME
and a column downloads.master
which is a boolean field to say which record is the master copy.
The following query successfully gets the records which have the most recent date:
SELECT t1.master
FROM downloads t1
WHERE t1.id = (SELECT t2.id
FROM downloads t2
WHERE t2.url_id = t1.url_id
ORDER BY t2.created DESC
LIMIT 1)
I want to update these records by setting master
to 1
.
Both the SELECT
and UPDATE
I want to perform apply to the same table, downloads
I have tried the following MySQL - UPDATE query based on SELECT Query :
UPDATE downloads
(
SELECT t1.master
FROM downloads t1
WHERE t1.id = (SELECT t2.id
FROM downloads t2
WHERE t2.url_id = t1.url_id
ORDER BY t2.created DESC
LIMIT 1)
)
SET master = 1
But this gives an error:
Error : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(
SELECT t1.master
FROM downloads t1
WHERE t1.id = (SELECT t2.id
' at line 2
Other solutions I tried on the above link updated the entire table, where as I'm just trying to update the records retrieved from the working SELECT
I have. Please can someone help point me in the right direction?