Find value which is not present in inner join? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

Find value which is not present in inner join?

We have two tables one named as table_1 and other named as table_2. In table_1 we have 250 rows with one primary key and in table_2 we have 300 rows with one foreign key which is mapped with primary key of table_1. I want a output with the remaing 50 rows in table_2?

3rd May 2017, 6:32 PM
Madhur Munjal
Madhur Munjal - avatar
5 ответов
+ 10
The rightmost option is your answer here: https://i.stack.imgur.com/3bs7C.png
3rd May 2017, 6:37 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
Exactly... why we need SQL challenges.
4th May 2017, 1:52 PM
Leon
Leon - avatar
+ 4
You need left join and chek for null, as in example (reference) above, or you can use subqueries. Somthing like select * from table_2 where ffk not in (select fpk from table_1)
3rd May 2017, 7:57 PM
shaldem
shaldem - avatar
+ 2
This is an efficient way if your SQL engine supports the EXISTS keyword: select * from table_2 where not exists (select 1 from table_1 where table_1.pk = table_2.fk);
10th May 2017, 9:35 AM
Brian
Brian - avatar
+ 1
Select all from table2 and left join with table1and take what columns u want
4th May 2017, 4:35 PM
mani kanta
mani kanta - avatar