I have to delete a row with max(id)
from a table in MySQL
.
I am using query::
DELETE
FROM master
WHERE id=(
SELECT MAX(id)
FROM master)
but getting error No. 1093
.
Can anybody please help me??
I have to delete a row with max(id)
from a table in MySQL
.
I am using query::
DELETE
FROM master
WHERE id=(
SELECT MAX(id)
FROM master)
but getting error No. 1093
.
Can anybody please help me??
You can't specify target table for update
in FROM
clause.
you can delete the last row as mentioned below.
DELETE FROM master ORDER BY id DESC LIMIT 1
You cant modify the same table from which you are selecting the data in subquery.
Try this -
DELETE m.*
FROM master m
WHERE id IN (SELECT id_temp from(
SELECT MAX(id) as id_temp
FROM master) x)
You can't specify target table for
Delete
inFROM clause
Try this
DELETE FROM master
WHERE id IN (SELECT A.MAXid FROM
(SELECT MAX(id) as MAXid FROM master) A
)