如何在同一个存储过程中选择多个插入的记录?
INSERT INTO cars (type, status_id)
VALUES ('GM',1),
('Toyota',2),
('Honda',3);
汽车有一个名为car_id的AUTO_INCREMENT PK字段。 我们说这个表已插入
1556 GM 1
1557丰田2
1558本田3
如何选择?
答案 0 :(得分:1)
好的,很容易解决。
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;
答案 1 :(得分:1)
您可以使用这两个函数的结果:
像这样: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
;