C#MySQL - 2个查询之间的差异

时间:2017-05-01 12:09:41

标签: c# mysql sql

我正在处理一个项目,下一部分我将需要比较2个查询的结果。

方案: 在表格中我保留了团队中的所有球员。 在另一张桌子上只有教练要求比赛的那些。

我想知道哪些球员被排除在外

我采取的最佳方法是什么?

我可以使用类似

的内容吗?
    (Query for Selecting all players)
    EXCEPT
    (Query for Selecting the ones called by the coach)

所有球员

   Number | Name
   ------ | ------
   23     | john 
   24     | Mario 

选定的球员

   Number | Name
   ------ | ------
   23     | john 

我希望它能够显示所选玩家表中缺少马里奥的结果

2 个答案:

答案 0 :(得分:1)

使用NOT EXISTS

select * from all_players p1
where not exists
(select 1 from players p2
where p1.number=p2.number
and p1.name=p2.name
--  and -- You can add other columns here
) t

使用LEFT JOIN

select p1.* from all_players p1
left join players p2
on p1.number=p2.number
and p1.name=p2.name
-- and p1.last_name=p2.last_name --add other columns
where 
(p2.number is null 
 and p2.name is null 
 -- and p2.last_name is null --add other columns
)

使用IN,如果有相同的键匹配

select * From all_players p
where number not in (select number from players)

答案 1 :(得分:0)

用户这个你可以得到你的结果

Select players from players_table where player not in (select coach_selected_player from coach_selected_player_table)

相关问题