Mysql left join with condition in right table

前端 未结 2 1136
说谎
说谎 2020-12-07 01:42

I have been trying to solve this issue for a while, hope anyone help me. I am having two table, the first table is

Table Name : OnlineTest

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 01:44

    Place the d.userid = 1 predicate in the ON clause:

    select c.onlinetestid, d.userid, d.status 
    from onlinetest c 
    left join userstatus d on d.onlinetestid = c.onlinetestid and d.userid = 1
    where c.category = 'English' 
    

    This will return all rows from onlinetest, having columns of userstatus filled with nulls where predicate d.userid = 1 fails.

提交回复
热议问题