MySql Inner Join with WHERE子句 [英] MySql Inner Join with WHERE clause

查看:332
本文介绍了MySql Inner Join with WHERE子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

 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'

我需要来自table1的信息,因为与f_com_id关联的所有id都为430,状态为已提交,并且该类型仅在存储在其他表(table2)中的状态中

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)

f_id分别是p_keyf_key.
但这给了我错误,我想我把WHERE子句放错了,如何解决.

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.?

错误消息:#1064-您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在'INNER JOIN table2附近使用正确的语法 在第2行的table2.f_id ='上

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

推荐答案

是的,您是对的.您将WHERE子句放置错了.您只能在单个查询中使用一个WHERE子句,因此对于以下多个条件请尝试AND:

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:

 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' 

这篇关于MySql Inner Join with WHERE子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆