Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql query didn't get proper payment method

Tags:

sql

mysql

I got issue while i execute my sql query with paymentmethod 1 show it's show paymentmethod 3 also. Please Check where i am wrong. Thanks in advance

Image From phpmyadmin with access sql query.

This is my sql query:-

SELECT (SELECT COUNT(u.`upperuserid`) 
         FROM user u 
         WHERE u.upperuserid = user.usernewid 
     ) as ref,
       usernewid,
       user.paymentmethod,usersecond, mod_date
from user 
HAVING ref <  2 or user.usersecond=0 and paymentmethod = 1
like image 320
kannu Avatar asked Sep 12 '26 13:09

kannu


1 Answers

ref <  2 or user.usersecond=0 and paymentmethod = 1

Operator precedence. This is being interpreted as:

(ref <  2) or (user.usersecond=0 and paymentmethod = 1)

Since the records in question match ref < 2, they are returned.

Explicitly define the precedence of your logic by grouping expressions in parentheses:

(ref <  2 or user.usersecond=0) and (paymentmethod = 1)
like image 164
David Avatar answered Sep 15 '26 04:09

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!