简体   繁体   English

使用MySQL进行IN后内部联接两个表上的SQL语法

[英]SQL syntax on inner join two table after IN using MySQL

I am having some trouble with the following sql query 我在以下sql查询中遇到问题

SELECT c.item1 ,c.id, a.id
FROM table_c as c
WHERE c.id IN
  (
   SELECT id
   FROM table_b
   WHERE someinfo = 'active'
  )
AND c.id IS NOT NULL
INNER JOIN table_a as a
ON c.id=a.id

The problem lies in the INNER JOIN 问题出在INNER JOIN

INNER JOIN table_a as a
ON c.id=a.id

Sequel Pro outputs Sequel Pro输出

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN 

Can someone give me some insight on this 有人可以给我一些见解吗

Without having tested: the Inner Join should be before the WHERE clause 未经测试:内部联接应该在WHERE子句之前

SELECT c.item1 ,c.id, a.id
FROM table_c as c
INNER JOIN table_a as a ON c.id=a.id
WHERE c.id IN
(
   SELECT id
   FROM table_b
   WHERE someinfo = 'active'
)
AND c.id IS NOT NULL

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

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