首页 > 解决方案 > 在 PostgreSQL 中使用 WHERE 子句时出现语法错误

问题描述

我正在尝试在 PostgreSQL 中运行一些与大学数据库相关的查询。为了找到来自不同部门的导师建议的学生,我使用了-

select distinct s_id from advisor
where (s_id ,i_id) in (select distinct student.id,instructor.id from
student join instructor where student.dept_name <> instructor.dept_name);

但是我收到以下错误:

错误:“where”处或附近的语法错误

第 3 行:学生加入讲师,其中 student.dept_name <> instructo...

有什么修复吗?

标签: sqlpostgresqlwhere-clause

解决方案


请试试这个:

select distinct s_id from advisor
where (s_id ,i_id) in (select distinct student.id,instructor.id from
student join instructor on student.dept_name <> instructor.dept_name);

而不是你需要使用on连接子句的地方。


推荐阅读