我有一个包含event_id
,eventname
,date
,time
,location
,user_id
的表格。每个用户ID可以有多个事件ID。我想查询最高事件ID,例如user id = 30
。怎么办呢?
答案 0 :(得分:2)
SELECT
MAX(event_id) as MEvent_id ,
eventname,
date,
time,
location,
user_id
FROM mytable
WHERE user_id = 30
答案 1 :(得分:2)
这非常简单。
SELECT MAX(event_id) FROM table WHERE user_id = 30
答案 2 :(得分:2)
SELECT a.*
FROM tableName a
INNER JOIN
(
SELECT userID, MAX(event_ID) maxID
FROM tableName
GROUP BY userID
) b ON a.userID = b.userID AND
a.event_ID = b.maxID
WHERE a.userID = 30