user1119096
user1119096

Reputation: 103

how to access data from mysql

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

Answers (3)

user562854
user562854

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

Mahmoud Gamal
Mahmoud Gamal

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

John Woo
John Woo

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

Related Questions