开发者

conditional merging of two tables in mysql

开发者 https://www.devze.com 2023-01-11 03:17 出处:网络
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 ses

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

精彩评论

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