我尝试做一些我觉得应该有点简单的事情。我有两个选择语句:
SELECT concat(st.fname,' ',st.lname) as Fullname, st.parent_phone
FROM student as st, grade as g, section as s, semester as sem
WHERE st.studentid=g.studentid AND g.sectionid=s.sectionid
AND s.semesterid=sem.semesterid AND s.semesterid not in (3, 4)
Group by Fullname;
返回此(模拟数据):
SELECT concat(st.fname,' ',st.lname) as Fullname, st.parent_phone
FROM student as st, grade as g, section as s, semester as sem
WHERE st.studentid=g.studentid AND g.sectionid=s.sectionid
AND s.semesterid=sem.semesterid AND s.semesterid in (3, 4)
Group by Fullname;
然后返回:
我想要做的是显示第一个语句中出现的三个记录,但不按字母顺序显示在第二个语句中。我想基本上从语句1中减去语句2中的所有记录。有人可以帮助我吗?
答案 0 :(得分:0)
尝试:
SELECT x.*
FROM (
-- the first subquery goes here
) x
LEFT JOIN (
-- the second subquery goes here
) y
ON x.full_name = y.full_name AND x.parent_phone = y.parent_phone
WHERE y.parent_phone IS NULL