如果你有下列表格:MYSQL - 找老師1和被給予的課程名稱2
course:
+---------------+---------------+
| id | Name |
|---------------|---------------|
| 1 | Maths |
| 2 | English |
| 3 | Art |
| 4 | Physics |
| 5 | Psychology |
+-------------------------------+
course_teacher:
+----------------------+---------------------+
| course_id | teacher_id |
|----------------------|---------------------|
| 1 | 1 |
| 2 | 1 |
| 1 | 2 |
| 2 | 2 |
| 3 | 2 |
+----------------------v---------------------+
我怎樣才能獲得通過教師1和2
給出課程名稱列表我的嘗試:SELECT DISTINCT(
COURSE_ID ) FROM
course_teacher WHERE
teacher_id IN (1,2);
但是,這種查詢過濾所有不過濾的雙重結果對教師1和2
基本「加入的cheatsheet」,我不能推薦這還不夠:http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/ – tedder42 2014-09-25 21:59:05