我有一个包含INNER JOIN的SELECT查询。我正在寻找一种方法来创建相同的查询,但没有任何类型的JOIN。这是我当前的查询;
SELECT loan.duedate, loan.no, student.name FROM loan
INNER JOIN student ON loan.no = student.no
ORDER BY loan.duedate DESC LIMIT 1
这是可能的吗?我将如何创建它?
答案 0 :(得分:2)
忽略'为什么'如果JOIN是1:1,您可以使用子选择而不是JOIN;
SELECT
loan.duedate,
loan.no,
(SELECT student.name FROM student WHERE student.no = loan.no) AS name
FROM
loan
ORDER BY
loan.duedate DESC
LIMIT 1
答案 1 :(得分:0)
简单到足以转换但内部连接更有意义。
SELECT loan.duedate, loan.no, student.name
FROM loan l,
student s
Where l.no = s.no
ORDER BY l.duedate DESC
LIMIT 1