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
我正在尝试根据event_id
获取最后插入的记录,此查询会带回所有记录。
类似于mysql_insert_id()
会做的事情。
是否可以修改查询以仅返回最后插入的记录?
我的数据看起来像这样我需要返回上一个event_id
及其匹配的res_id
event_id | res_id
116 | 1
116 | 2
答案 0 :(得分: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)