Mysql 如何检查列值是否不为null,然后使用sql查询检查下一列

Mysql 如何检查列值是否不为null,然后使用sql查询检查下一列,mysql,sql,Mysql,Sql,在我上面的查询中,如果testtb.id不为null,我想再使用一个where条件(即where testtb.name不为null),您可以使用AND子句 SELECT users.group_id, testtb.id FROM users LEFT JOIN testtb on users.group_id =testtb.id where testtb.id is not null ORDER BY users.group_id 您可以使用: 您的意思是使用where子句:其中t

在我上面的查询中,如果
testtb.id不为null,我想再使用一个
where
条件(即
where testtb.name不为null
),您可以使用AND子句

SELECT users.group_id, testtb.id 
FROM users 
LEFT JOIN testtb on users.group_id =testtb.id 
where testtb.id is not null ORDER BY users.group_id
您可以使用:


您的意思是使用where子句:
其中testtb.id不为null,testtb.name不为null
?如果我的testtb.id不为null,则testtb.name不为null应为work,否则testtb.name2不为null应为workOk,明白了,请检查
    SELECT users.group_id, testtb.id FROM users 
    LEFT JOIN testtb on users.group_id =testtb.id 
    AND testtb.id is not null 
AND testtb.name is not null
    ORDER BY users.group_id;
SELECT users.group_id, testtb.id 
FROM users 
LEFT OUTER JOIN testtb on users.group_id =testtb.id 
where testtb.id is not null 
and testtb.name is not null
ORDER BY users.group_id
SELECT users.group_id, testtb.id 
FROM users 
LEFT JOIN testtb on users.group_id =testtb.id 
where testtb.id is not null 
AND COALESCE(testtb.name1,testtb.name2,testtb.name3) IS NOT NULL
ORDER BY users.group_id