How to select multiple inserted records in same stored procedure?
INSERT INTO cars (type, status_id)
VALUES ('GM',1),
('Toyota',2),
('Honda',3);
cars has an AUTO_INCREMENT PK field called car_id. let's say the table was inserted
1556 GM 1
1557 Toyota 2
1558 Honda 3
How can I select it?
Ok, was pretty easy to solve.
declare new_cars int;
INSERT INTO cars (name, type)
VALUES ('GM',1),
('Toyota',2),
('Honda',3);
select row_count() into new_cars;
select * from cars
order by car_id desc
limit new_cars;
You could use the results of these two functions:
like this:
INSERT INTO cars (type, status_id)
VALUES ('GM',1),
('Toyota',2),
('Honda',3);
SELECT *
FROM cars
WHERE car_id BETWEEN LAST_INSERT_ID()
AND LAST_INSERT_ID() + ROW_COUNT() - 1
;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.