-1

Table User id, name

Table Connection

id, user_id, active

User can have multiple connections with active fields from 0 to 3

When I do left join I am getting all connection for each user. That is fine. What I am looking for is how to find users who has few connections but its missing number 1 in active so he has few connections active 0, one active 2 but no active 1.

Any ideas???

  • Your question is not clear. Please elaborate it properly That is fine. What I am looking for is how to find users who have few connections but its missing number 1 in active so he has few connections active 0, one active 2 but no active 1. – Rajesh Ranjan Jul 19 at 16:43
  • Please consider reading this advice – mustaccio Jul 19 at 17:01
  • Please show us the query, EXPLAIN SELECT ..., and SHOW CREATE TABLE. – Rick James Jul 19 at 18:12
  • HAVING SUM(active=0)>1 AND SUM(active=1)=0 AND SUM(active=2)=1 – Akina Jul 19 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.