我如何获取数据不在另一个表中[关闭]

问题描述 投票:-1回答:1
现在我有3张桌子

1。表:老师

Id_Users ID_Teacher Fname Lname --------------------------------------------- 1 abc Jhon Smith 2 abb MIx Gordon 3 aba Jim Tomson

2。表格:学生

Id_Users ID_Student Fname Lname --------------------------------------------- 4 xyz Anderson baker 5 zxc Emily Smoke 6 cvx Anny Jane

3。表格:Inteam

Id_Inteam ID_Users(FK) ID_Team ID_Activities -------------------------------------------------------- 1 1 1 11 2 3 2 12 3 4 1 11

我需要让老师和学生在表In_Team和ID_Activities中不存在的位置!= 11

我如何创建查询。请帮助

mysql sql codeigniter codeigniter-3
1个回答
0
投票
您可以使用左联接不匹配

select t.Id_Users , t.ID_Teacher , t.Fname , t.Lname , u.Fname , u.Lname from Teacher t inner join left join In_Team i ON i.id_users = t.id_users ID_Activities != 11 where i.id_users is null

© www.soinside.com 2019 - 2024. All rights reserved.