[英]Mysql Inner Join two table
I have two tables carry and transactions, and want to select member records from transaction table where purpose=5 based on the same member id in carry table with left_carry or right carry != 0. 我有两个表进位和事务,并且要基于带有left_carry或right进位!= 0的进位表中的相同成员ID,从目的= 5的事务表中选择成员记录。
I tried with the sql bellow but getting duplicate and multiple purpose data from transaction table. 我尝试使用SQL波纹管,但从事务表中获取重复数据和多用途数据。 the result is as in the link: http://prntscr.com/9tles2
结果如链接中所示: http : //prntscr.com/9tles2
My code is: 我的代码是:
select distinct c.member_id,c.left_carry,c.middle_carry, t.purpose
from carry c
inner join transactions t on t.member_id = c.member_id
where c.left_carry != 0 or c.middle_carry != 0 and t.purpose = 1
Mixing OR and AND can be a little confusing. 混合使用OR和AND可能会有些混乱。 It is best to add some brackets to make it clear what is intended.
最好添加一些括号以使内容清楚。
This should clear up your problem 这应该可以解决您的问题
select distinct c.member_id,c.left_carry,c.middle_carry, t.purpose
from carry c
inner join transactions t on t.member_id = c.member_id
where ( c.left_carry != 0
or c.middle_carry != 0)
and t.purpose = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.