我想隐藏id如果不喜欢但不工作选择*从character,character\u actor where character.id不喜欢character\u actor.character\u id;

6tdlim6h  于 2021-06-21  发布在  Mysql
关注(0)|答案(3)|浏览(329)

我想隐藏身份证,如果不喜欢,但不工作
选择*from character,character\u actor where character.id不喜欢character\u actor.character\u id;

id  name    id  character_id    actor_name
1   Doogie Howser   1   4       Alyson Hannigan
1   Doogie Howser   2   3       Alyson Hannigan
1   Doogie Howser   3   2       Neil Patrick Harris
2   Barney Stinson  1   4       Alyson Hannigan
2   Barney Stinson  2   3       Alyson Hannigan
2   Barney Stinson  4   1       Neil Patrick Harris
3   Lily Aldrin     1   4      Alyson Hannigan
3   Lily Aldrin     3   2    Neil Patrick Harris
3   Lily Aldrin     4   1    Neil Patrick Harris
4   Willow Rosenberg 2  3   Alyson Hannigan
4   Willow Rosenberg 3  2   Neil Patrick Harris
4   Willow Rosenberg 4  1   Neil Patrick Harris
9wbgstp7

9wbgstp71#

您需要一个“不在”查询:

SELECT *
FROM character WHERE character.id NOT IN (SELECT character_actor.character_id from character_actor)

它也可以通过一个不存在的。根据dbms和结构的不同,这可能会导致更好的性能。

SELECT *
FROM character c WHERE NOT EXISTS(SELECT NULL from character_actor ca WHERE ca.character_id=c.id)
n8ghc7c1

n8ghc7c12#

尝试此查询

SELECT *
FROM character as c JOIN character_actor as ca
ON c.character_id != ca.character_id
3wabscal

3wabscal3#

例如,我有两个表,我想得到两个\u table.name而不是一个\u table.name

one_table
id  name    
1   Dave    
2   Mary    
3   Fry male    
4   Leela   
5   Odie    

two_table
id  name    
1   Dave    
2   Mary    
3   Fry male    
4   Leela   
5   Odie    
6   Jumpy   
7   Sneakers
8   Jack
9   Malia
10  Lee

相关问题