Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

การจำลอง INTERSECT query ใน MySQL


MySQL ไม่มี INTERSECT ใช้ IN operator จำลอง ตัวอย่างตารางเดียวกันกับข้อ 177 หา studentid ที่มีในทั้งสองตาราง:

mysql> Select Student_detail.studentid FROM Student_detail WHERE student_detail.studentid IN(SELECT Student_info.studentid FROM Student_info);
+-----------+
| studentid |
+-----------+
|       101 |
|       105 |
|       130 |
|       132 |
|       133 |
+-----------+
5 rows in set (0.06 sec)

ได้ 5 ค่า studentid ที่ปรากฏในทั้งสองตาราง