简体   繁体   English

从一个表中选择表行,其中另一个表中的表列的值为x

[英]Selecting table rows from one table where value of table column in another table is x

I am trying to SELECT rows from a table where it has got a foreign key on second table and the key from the second table is used in a third table as foreign key. 我试图从表中选择行,该表在第二个表上有外键,而第二个表中的键在第三个表中用作外键。 How can I retrieve the rows from the first table where on the third table doesn't have the key from the second table which this particular key's row has got the first tables' row's primary key as foreign key and also on the third table it hasn't got the foreign key of the fourth table. 我如何从第一张表中检索行,而第三张表上没有第二张表中的键,该特定键的行已将第一张表的行的主键作为外键,并且在第三张表中也没有没有第四张桌子的外键。

I tried using inner join but it only works with SELECTING rows where it has got a specify value rather than not having this specify value. 我尝试使用内部联接,但它仅适用于具有指定值而不是没有此指定值的SELECTING行。

Please help me 请帮我

Faculty table 教职员工表

FaculID | FaculName | FaculLocation |

Course table 课程表

CourseID | CourseName | CourseDescription

FacultyCourse table 学院课程表

fcID | CourseID | FaculID

Registeration table 登记表

RegID | fcID | stuID

Student table 学生桌

stuID | stuName | stuAge | stuAddress

so basically what i want to do now is get all bid where the e table hasn't got uid and did(which has got a bid foreign key). 所以基本上我现在想做的是在e表没有uid和do(有一个出价外键)的地方获得所有出价。

Try to use LEFT OUTER JOIN: 尝试使用LEFT OUTER JOIN:

SELECT a.*
FROM a
LEFT OUTER JOIN b on a.keya = b.keybjoina
LEFT OUTER JOIN c on b.keybjoina = c.keycjoinb
WHERE c.keycjoinb IS NULL

Try: 尝试:

(change table and column names as appropriate) (适当更改表和列的名称)

updated based on example layout 根据示例布局更新

select *
  from faculty
 where faculid not in (select faculty.FaculID
                         from faculty
                         join facultycourse 
                           on faculty.FaculID = FacultyCourse.FaculID
                         join registration
                           on registration.fcid = FacultyCourse.fcid
                        where registration.stuid = 'XYZ');

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM