Ozerich
Ozerich

Reputation: 2000

SQL: How to select variable value?

I have a query

INSERT INTO ... SET ....; 
SET @last_id = LAST_INSERT_ID();
INSERT INTO ... SET .... ,item_id = @last_id;
INSERT INTO ... SET .... ,item_id = @last_id;

And i want to output to result value of variable. for example:

SELECT @last_id as ID;

query:

INSERT INTO `targets` SET `name` = '123';
SET @target_id = LAST_INSERT_ID();
SELECT @target_id as id;

Upvotes: 0

Views: 159

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 158009

This is not a query, but rather a set of queries.
Just run them one by one in order.

Upvotes: 1

Related Questions