MySql内部连接与WHERE子句

时间:2022-04-05 00:09:51

Here is my code:

这是我的代码:

 SELECT table1.f_id  FROM table1 WHERE table1.f_com_id = '430' AND      
 table1.f_status = 'Submitted' 
 INNER JOIN table2
 ON table2.f_id = table1.f_id
 where table2.f_type = 'InProcess'

I need information from table1 as all the id associated with f_com_id as 430 and status as submitted and the type should be only in process which is stored in other table(table2)

我需要表1中的信息作为与f_com_id相关的所有id为430和提交的状态,类型应该只存储在另一个表中(表2)

f_id is p_key and f_key in both the tables.
But this giving me errors, I think I am placing the WHERE clause wrong, how to fix it.?

f_id是两个表中的p_key和f_key。但是这给我带来了错误,我想我把WHERE子句放错了,怎么修正呢?

Error msg: #1064 - 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 table2 ON table2.f_id = ' at line 2

错误msg: #1064 - SQL语法中有错误;检查与MySQL服务器版本相对应的手册,找到在表2上使用“内部连接表2”的正确语法。f_id = '在第2行

4 个解决方案

#1


32  

Yes you are right. You have placed WHERE clause wrong. You can only use one WHERE clause in single query so try AND for multiple conditions like this:

是的,你是对的。你把WHERE子句写错了。您只能在单个查询中使用一个WHERE子句,因此请尝试使用以下多个条件:

 SELECT table1.f_id  FROM table1 
   INNER JOIN table2
     ON table2.f_id = table1.f_id
 WHERE table2.f_type = 'InProcess'
   AND f_com_id = '430'
   AND f_status = 'Submitted' 

#2


4  


1. Change the INNER JOIN before the WHERE clause.
2. You have two WHEREs which is not allowed.

1。在WHERE子句之前更改内部连接。2。你有两个地方是不允许的。

Try this:

试试这个:

SELECT table1.f_id FROM table1
  INNER JOIN table2 
     ON (table2.f_id = table1.f_id AND table2.f_type = 'InProcess') 
   WHERE table1.f_com_id = '430' AND table1.f_status = 'Submitted'

#3


1  

You could only write one where clause.

你只能写一个where子句。

 SELECT table1.f_id  FROM table1
 INNER JOIN table2
 ON table2.f_id = table1.f_id
 where table1.f_com_id = '430' AND      
 table1.f_status = 'Submitted' AND table2.f_type = 'InProcess'

#4


-2  

You are using two WHERE clauses but only one is allowed. Use it like this:

您正在使用两个WHERE子句,但只允许使用一个。使用它是这样的:

SELECT table1.f_id FROM table1
INNER JOIN table2 ON table2.f_id = table1.f_id
WHERE
  table1.f_com_id = '430'
  AND table1.f_status = 'Submitted'
  AND table2.f_type = 'InProcess'

#1


32  

Yes you are right. You have placed WHERE clause wrong. You can only use one WHERE clause in single query so try AND for multiple conditions like this:

是的,你是对的。你把WHERE子句写错了。您只能在单个查询中使用一个WHERE子句,因此请尝试使用以下多个条件:

 SELECT table1.f_id  FROM table1 
   INNER JOIN table2
     ON table2.f_id = table1.f_id
 WHERE table2.f_type = 'InProcess'
   AND f_com_id = '430'
   AND f_status = 'Submitted' 

#2


4  


1. Change the INNER JOIN before the WHERE clause.
2. You have two WHEREs which is not allowed.

1。在WHERE子句之前更改内部连接。2。你有两个地方是不允许的。

Try this:

试试这个:

SELECT table1.f_id FROM table1
  INNER JOIN table2 
     ON (table2.f_id = table1.f_id AND table2.f_type = 'InProcess') 
   WHERE table1.f_com_id = '430' AND table1.f_status = 'Submitted'

#3


1  

You could only write one where clause.

你只能写一个where子句。

 SELECT table1.f_id  FROM table1
 INNER JOIN table2
 ON table2.f_id = table1.f_id
 where table1.f_com_id = '430' AND      
 table1.f_status = 'Submitted' AND table2.f_type = 'InProcess'

#4


-2  

You are using two WHERE clauses but only one is allowed. Use it like this:

您正在使用两个WHERE子句,但只允许使用一个。使用它是这样的:

SELECT table1.f_id FROM table1
INNER JOIN table2 ON table2.f_id = table1.f_id
WHERE
  table1.f_com_id = '430'
  AND table1.f_status = 'Submitted'
  AND table2.f_type = 'InProcess'