如果workspace.assigned_to = NULL
ELSE不选择任何内容,如何选择列。
SELECT workspace.*, projects.*,
CASE
WHEN workspace.assigned_to != NULL
THEN users.user_id,users.first_name, users.last_name
END FROM workspace
INNER JOIN projects ON workspace.workspace_id = projects.project_id
INNER JOIN users ON workspace.assigned_to = users.user_id
WHERE project_id=:project_id
最佳答案
SELECT workspace.*, projects.*,
users.user_id,users.first_name, users.last_name
FROM workspace
INNER JOIN projects ON workspace.workspace_id = projects.project_id
LEFT JOIN users ON workspace.assigned_to = users.user_id
WHERE project_id=:project_id
LEFT JOIN表示我们通过Assigned_to加入用户,但如果为null,则用户的valuea为null
关于mysql - mysql中的SELECT中的IF语句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34378991/