简体   繁体   English

在 PostgreSQL 中使用 WHERE 子句时出现语法错误

[英]Syntax error while using WHERE clause in PostgreSQL

I'm trying to run some queries related to the University database in PostgreSQL.我正在尝试运行一些与 PostgreSQL 中的大学数据库相关的查询。 To find students advised by instructors from different departments, I used-为了找到来自不同部门的导师建议的学生,我使用了-

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);

However im getting the following error:但是我收到以下错误:

ERROR: syntax error at or near "where"错误:“where”处或附近的语法错误

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

Any fix?有什么修复吗?

Please try this:请试试这个:

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);

Instead of where you need to use on clause with join.而不是你需要在哪里使用带有连接的on子句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM