开发者

conditional merging of two tables in mysql

i have 2 tables called user, with the fileds user.userID and 开发者_运维百科user.lastActivityTime, and session with the same fields. Now i want to get an user by ID but if there is an entry in the sessionTable with the same userID i want to get all from user but the lastActivityTime from session. How can I do this?

Thank You


SELECT * FROM user LEFT JOIN session ON user.UserID=session.UserID

And use session.lastActivityTime preferentially if it is not null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜