简体   繁体   English

如何 select 记录在另一个表中没有链接记录是 null?

[英]How to select records where no linked records in another table are null?

I have the following SQL:我有以下 SQL:

SELECT tournaments_blg.tournament_id_blg
FROM matches_blg  LEFT JOIN tournaments_blg ON tournaments_blg.tournament_id_blg = matches_blg.tournament_id_blg
WHERE matches_blg.match_id_op IS NULL
GROUP BY tournaments_blg.tournament_id_blg

This selects all tournaments_blg.tournament_id_blg where any one of matches_blg.match_id_op is NULL .这将选择所有tournaments_blg.tournament_id_blg _blg.tournament_id_blg,其中任何一个matches_blg.match_id_opNULL

How would I only select all tournaments_blg.tournament_id_blg if ALL the matches_blg.match_id_op are NULL ?如果所有matches_blg.match_id_op都是NULL tournaments_blg.tournament_id_blg

SELECT tb.tournament_id_blg
FROM tournaments_blg tb
LEFT JOIN matches_blg mb ON tb.tournament_id_blg = mb.tournament_id_blg 
                        AND mb.match_id_op IS NOT NULL
WHERE mb.tournament_id_blg IS NULL

or或者

SELECT tb.tournament_id_blg
FROM tournaments_blg tb
WHERE NOT EXISTS ( SELECT NULL
                   FROM matches_blg mb 
                   WHERE tb.tournament_id_blg = mb.tournament_id_blg 
                     AND mb.match_id_op IS NOT NULL )

Try this:尝试这个:

SELECT tournaments_blg.tournament_id_blg FROM matches_blg WHERE matches_blg.match_id_op NOT IN (Select tournaments_blg from tournaments_blg )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何选择不在另一个表中的记录? - How to select records that are not in another table? 从表中选择记录,其中给定的列值在另一列中没有非空值 - Select records from table where a given column value has no non-null values in another column MySQL如何在一个表中有条件的表中选择一个表中的特定记录(多对一)? - MySQL How to select specific records in one table join (1-many) in another table where records have condition on 1 field? MySQL - 选择表中的记录,其中另一个表中的任何关联记录都不等于某个值 - MySQL - Select records in a table where none of the associated records in another table equal a certain value 仅选择带有链接记录的记录 - Select only records with linked records 如何根据条件选择一个表中的所有记录,而第二个表中没有记录 - How to select all records in one table where no records in second table based on criteria 我如何显示一个表中的记录,其中输出记录的数量取决于另一张表 - How can i display records from one table where the number of outputed records depend on another table Select 表记录来自另一个表 - Select table records from another table 选择其中ID在另一个表中且状态= 1的记录 - Select records where ID is in the other table and status = 1 mysql-WHERE记录在另一个表中没有记录 - mysql - WHERE records does not have records in another table
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM