![](/img/trans.png)
[英]MySQL select data from table and inner join the union all selection from another two identical tables
[英]How to Select data from two tables which are not identical on another table using WHERE condition in MySQL
我有两个表,分别是“ 学生 ”和“ 用户 ”。 我想从“Student”表中选择first_name和Last_name,它与用户表的“Student_ID”不匹配。
SELECT student.student_id,
student.first_name,
student.last_name
FROM student,
USER
WHERE student.student_id != USER.student_id
与NOT IN
版本相同,但执行得更好一些。 根据这个: https : //www.eversql.com/sql-syntax-check-validator/
SELECT
student.student_id,
student.first_name,
student.last_name
FROM
student
WHERE
NOT EXISTS (
SELECT
student_id
from
user
where
user.student_id = student.student_id
)
尝试使用此查询:
SELECT firstname,lastname
FROM Student
WHERE ID NOT IN(SELECT Student_ID from User);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.