1

i have a little problem with mysql. query is follow:

SELECT u.user_id,u.gender, ua.age,u.name,u.isonline,dot.profile_image_no FROM user_table AS u
INNER JOIN user_answers_table AS ua ON u.user_id = ua.user_id
INNER JOIN data_one_table AS dot ON dot.user_id = u.user_id
INNER JOIN user_detail_table AS udt ON udt.user_id = u.user_id
WHERE u.isregistrationcomplete='1' AND u.isactive='1' AND u.gender = '0' AND ua.age >= '20' AND ua.age <= '24' AND udt.lookingfor = '1' OR udt.lookingfor = '3';

i want to get only u.gender = '0' users but that query return to me with u.gender = '1' so where is the problem?

query result:

user_id  gender     age  name         isonline  profile_image_no  
-------  ------  ------  -----------  --------  ------------------
    62       0      29  Wqasaasd            1                   1
    93       1      28  Sadasda             1                   1
    131       0      26  Wedsas              1                   1
    155       0      91  Wwsfwdf             1                   1
    173       0      23  Yirmi30             1                   1
    220       0      20  Fjalekalimi         1                   1
    232       0      20  Seeemani            1                   1
    236       0      21  Mesut               1                   1
    238       0      89  23wdsca             1                   1
    247       0      23  11eqwe              1                   1
    252       0      24  Workhard            1                   1
    253       0      25  Sdsdg               1                   1
    343       1      25  Emily               1                   1

2 Answers 2

4

Stick your OR inside a bracket and try again!

SELECT u.user_id,u.gender, ua.age,u.name,u.isonline,dot.profile_image_no FROM user_table AS u
INNER JOIN user_answers_table AS ua ON u.user_id = ua.user_id
INNER JOIN data_one_table AS dot ON dot.user_id = u.user_id
INNER JOIN user_detail_table AS udt ON udt.user_id = u.user_id
WHERE u.isregistrationcomplete='1' 
AND u.isactive='1' 
AND u.gender = '0' 
AND ua.age >= '20' 
AND ua.age <= '24' 
AND (udt.lookingfor = '1' OR udt.lookingfor = '3');
Sign up to request clarification or add additional context in comments.

Comments

2

Bad logical syntax:

AND (udt.lookingfor = '1' OR udt.lookingfor = '3');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.