[英]How to retrive the last inserted id using mysql?
SELECT event.event_name, restaurants.res_name
FROM event_choices
INNER JOIN restaurants
ON event_choices.res_id = restaurants.res_id
INNER JOIN event
ON event_choices.event_id = event.event_id
I am trying to get the last inserted records based on the event_id
this query brings back all the records. 我试图根据event_id
获取最后插入的记录此查询带回所有记录。
similar to what mysql_insert_id()
would do. 类似于mysql_insert_id()
会做的事情。
Is it possible to modify the query to return only the last inserted record? 是否可以修改查询以仅返回最后插入的记录?
my data looks like this I need to return the last event_id
and its matching res_id
我的数据看起来像这样我需要返回最后一个event_id
及其匹配的res_id
event_id | res_id
116 | 1
116 | 2
SELECT event.event_name, restaurants.res_name
FROM event_choices
INNER JOIN restaurants ON event_choices.res_id = restaurants.res_id
INNER JOIN event ON event_choices.event_id = event.event_id
WHERE event.event_id = (SELECT MAX(event_id) FROM event)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.