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
where testtb.name is not null
条件(即testtb.id is not null
)
答案 0 :(得分:0)
您可以使用AND子句
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;
答案 1 :(得分:0)
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
答案 2 :(得分:0)
您可以使用coalesce:
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