[英]Php MySQL query to get max of event id for specific user id
I have a single table with event_id
, eventname
, date
, time
, location
, user_id
. 我有一个带有
event_id
, eventname
, date
, time
, location
, user_id
。 Each user Id can have multiple event ids. 每个用户ID可以具有多个事件ID。 I want to query for just the highest event id where
user id = 30
for example. 我只想查询最高事件ID,例如,
user id = 30
。 How can this be done? 如何才能做到这一点?
SELECT
MAX(event_id) as MEvent_id ,
eventname,
date,
time,
location,
user_id
FROM mytable
WHERE user_id = 30
这非常简单。
SELECT MAX(event_id) FROM table WHERE user_id = 30
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.