问题是放置ORDER BY
在WHERE
子查询语句。sql语法不允许您在WHERE
子句中对子查询的元素进行排序,因为它不会整体改变查询的结果。
您应该将其移出以修复语法:
SELECT empid FROM employees WHERE deptid IN
(
SELECT deptid FROM department WHERE description LIKE '%application%'
)
ORDER BY createddate DESC
createddate
不是employees
表格中的一列。它仅存在于department
表中
然后,您需要连接到department
表,并在表的ORDER BY
其中一列上使用:
SELECT e.empid
FROM employees e
JOIN department d ON e.deptid = d.deptid
WHERE d.description LIKE '%application%'
ORDER BY d.createddate DESC