sql - Cannot find correct number of values in a table that are not in another table, though I can do otherwise -



sql - Cannot find correct number of values in a table that are not in another table, though I can do otherwise -

i want retrieve course_id in table course not in table takes. table takes contains course_id of courses taken students. problem if have:

select count (distinct course.course_id) course, takes course.course_id = (takes.course_id);

the result 85 smaller total number of course_id in table course, 200. result correct.

but want find number of course_id not in table takes, , have:

select count (distinct course.course_id) course, takes course.course_id != (takes.course_id);

the result 200, equal number of course_id in table course. wrong code?

this sql give count of course_id in table course of study aren't in table takes:

select count (*) course of study c not exists (select * takes t c.course_id = t.course_id);

you didn't specify dbms, however, sql pretty standard should work in popular dbmss.

sql count

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -