0

My two table are like

Table 1


uid     mail


1136    [email protected]
1231    [email protected]

And

Table 2

uid     rid

1136    3
1136    7
1231    5
1231    2

So I want to join these both tables and want to get the result uid where rid in table 2 is not equal to 3.

Please let me know if you doesn't understand my requirement.

2
  • So what's your expected output? and what have you tried? Commented Jul 23, 2013 at 9:24
  • SELECT mail FROM users LEFT JOIN users_roles ON (users.uid = users_roles.uid AND users_roles.rid <> '3'). But although uid 1136 is having rid 3 but it still came in result. I don't want that Commented Jul 23, 2013 at 9:24

2 Answers 2

2
select t1.uid, mail, rid
from table1 t1
join table2 t2
on t1.uid = t2.uid and t2.uid not in (select uid from table2 where rid = 3)
Sign up to request clarification or add additional context in comments.

3 Comments

This is not correct as this query will also return 1136 which has rid 3. But I don't want that. I only want 1231 here as there is no rid 3 for that.
Yes i can see that let me check. Thanks
Do you have any other solution than this although it's working but very time consuming.
0
select t1.uid, mail, group_concat(rid) as rids
from table1 t1
left join table2 t2
on t1.uid = t2.uid
group by t1.uid
having not find_in_set(3,rids)
;

fiddle

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.