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.
精彩评论