table stockholders
stockholder_id election_id user_id
1 1 1
2 1 2
3 2 3
table users
user_id user_type
1 1
2 1
3 1
4 1
5 1
select
*
from
tbl_users
left join tbl_stockholders
on tbl_stockholders.user_id = tbl_users.user_id
where
user_type=1
and stockholders.user_id is null
and election_id <> 1
i want to search election_id not equal to 1 and user type equal to 1
stockholder_id election_id user_id user_type
3 2 3 1
null null 4 1
null null 5 1
this is an update
sorry my problem should be excluding the tbl_stockholders from the tbl_users with the parameter election_id.. because a problem exist when i have a duplicate user_id
table stockholders
stockholder_id election_id user_id
1 1 1
2 1 2
3 2 3
4 1 3
in the previous answer this is the result when election_id<>2
stockholder_id election_id user_id user_type
3 1 3 1
null null 4 1
null null 5 1
this must be
stockholder_id election_id user_id user_type
null null 4 1
null null 5 1
this is my current not working code
select * from tbl_users where not exists (select * from tbl_stockholders where election_id <> 2)
tbl_stockholders.user_id is nullin your query? Especially sincetbl_stockholdersis on the left of yourleft join?