Mysql 在sql server中基于子表条件从主表获取数据

Mysql 在sql server中基于子表条件从主表获取数据,mysql,sql-server,Mysql,Sql Server,需要根据子表条件从主表中提取数据 主表:- ID Name Address 1 abc xyz 2 abs txt 3 aui tre 4 pop top 5 the tre 6 pot tos 7 pog sop 8 pat top 9 bat cric 10 not kot 子表:- chid shootid imagename IDFK 101 234 123ab.jpg

需要根据子表条件从主表中提取数据

主表:-

ID Name Address

1   abc   xyz
2   abs   txt
3   aui   tre
4   pop   top
5   the   tre
6   pot   tos
7   pog   sop
8   pat   top
9   bat   cric
10  not   kot
子表:-

chid shootid imagename       IDFK
101   234    123ab.jpg        3
102   234    54abcab.jpg      3
103   235    123abc.jpg       3
104   236    12390acb.jpg     Null
105   235    12332aab.jpg     8
106   234    123786ab.jpg     4
107   234    54789abcab.jpg   10
108   235    122343abc.jpg    10
109   235    122123acb.jpg    4
110   234    12123aab.jpg     9
111   234    1223ab.jpg       Null
112   233    5432abcab.jpg    Null
113   235    1239abc.jpg      Null
114   236    1238acb.jpg      2
115   236    12356aab.jpg     2
116   236    1235ab.jpg       2
117   236    545abcab.jpg     Null
118   237    1233abc.jpg      1
119   237    1223acb.jpg      1
120   237    1123aab.jpg      1
子表中的IDFK是外键,主表中的ID是主键。 现在,我想显示主表中不存在于shootid上的子表过滤器上的名称,比如childtable.shootid=234。我试过了,但没有找到想要的输出。每次它返回时,对于不同的shootid也是一样的


请帮助我并向我展示正确的查询。

我不知道我是否理解你,但我认为这是你想要的

Select * from [master] m
where m.ID not in (Select IDFK from detail where shootid=234)

我想这就是你要找的

 Select distinct m.name from master m LEFT OUTER JOIN child c
     ON m.id = c.id and 
        c.shootid=234    
    where 
     c.id is null  

请使用您给出的示例表中的行添加所需输出。对于SHOT 234,您有多个IDFK值,您是在尝试从主控获取与这些值对应的行,还是与这些值不对应的行?很抱歉,这无法提供所需的输出,我也尝试了这种方法。