根据两个表的同一列中“数量”的差异选择查询结果

时间:2012-03-07 18:04:06

标签: mysql database

表1:

emp_id  course_id
 ______  _________
12345      4
23455      5
67890      6

表2:

course_id  course_name
_________  ___________
   1        English
   2        Mathematics
   3        Science
   4        G.K.
   5        c++
   6        JSP
   7        ASP

需要的表格 表3:

course_id  course_name
_________  ___________
   1        English
   2        Mathematics
   3        Science
   7        ASP

如何在MySQL中打印表3,同时考虑表1和表2中course_id的差异。(table2.course_id - table1.course_id)

1 个答案:

答案 0 :(得分:1)

select course_id, course_name
from table2
where course_id not in (select course_id from table1)