假设我想得到logId
,userId
,updated
,updatedById
,其中logId
大于找到的最低logId
这个userId
。
我试过了:
SELECT * FROM
(
SELECT logId, userId, updated, updatedById
FROM users_updatelog
WHERE userid=548
) AS tbl1
WHERE (tbl1.logId > (SELECT MIN(tbl1.logId) FROM tbl1))
ORDER BY tbl1.updated DESC
但这不对。我无法从subqueried表tbl1查询(错误消息:无效的对象名称'tbl1')
感谢任何提示。
答案 0 :(得分:4)
SELECT logId, userId, updated, updatedById
FROM users_updatelog
WHERE userid = 548
AND logId > (SELECT min(logId) FROM users_updatelog WHERE userid = 548)
ORDER BY updated DESC
答案 1 :(得分:1)
SELECT logId, userId, updated, updatedById
FROM users_updatelog
WHERE userid=548
AND logId > (SELECT MIN(logId) FROM users_updatelog WHERE userid=548)
ORDER BY updated DESC