Reputation: 103
START TRANSACTION;
SELECT * FROM tab1 WHERE 1 LIMIT 1;
DELETE FROM tab1 WHERE id="{HOW TO ACCESS ID FROM THE SELECT ABVOE?}"
COMMIT;
What I'm looking for is the solution to the problem.
Upvotes: 0
Views: 85
Reputation:
This is the SQL code you need, in order to achieve what you've asked for.
START TRANSACTION;
DELETE
FROM tab1
WHERE id IN (
SELECT id
FROM tab1
WHERE 1=1
LIMIT 1
)
COMMIT;
In order to pass the results back to PHP, you have to use Triggers.
Upvotes: 0
Reputation: 79939
I think What you need is this:
START TRANSACTION;
DELETE FROM tab1
where id = (SELECT id FROM tab1 WHERE /*your condition here*/);
COMMIT;
Edit: Based on the OP' comment below, There is no way to tell which row was the last deleted one, but you can create a Trigger to do that for you, See This tutorial.
Upvotes: 1
Reputation: 263733
from your query:
START TRANSACTION;
SELECT * FROM tab1 WHERE 1 LIMIT 1;
DELETE FROM tab1 WHERE id="{HOW TO ACCESS ID FROM THE SELECT ABVOE?}"
COMMIT;
i believed that you want to delete the first record on the table. you can get a hint from this example:
START TRANSACTION;
SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summary=@A WHERE type=1;
SELECT @A as UpdateID;
COMMIT;
Upvotes: 0