Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if all values in a column of one table exists in another table

I wanted to know the command to check if all the values in one table(created using select statement) is present in the other table (created using select command) all in one select statement.for eg ,i have a attribute fid and faculty_name in faculty table and fid ,class_name, room_no in another. how do i check all faculty who teaches in all the room present?

like image 895
user1783427 Avatar asked Nov 21 '25 01:11

user1783427


1 Answers

Poorly asked question, but

--
-- all faculty without a class
--
select *
from faculty f
where not exists ( select *
                   from class c
                   where c.fid = f.fid
                 )
--
-- all classes wihout faculty
--
select *
from class c
where not exists ( select *
                   from faculty f
                   where f.fid = c.fid
                 )
--
-- all-in-one. Each returned row represents
-- either a faculty or class without a match
-- in the other
--
select *
from      faculty f
full join class   c on c.fid = f.fid
where c.fid is null
   or f.fid is null
like image 163
Nicholas Carey Avatar answered Nov 23 '25 16:11

Nicholas Carey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!