I have three tables (admin,domain,user) as shown below
- ‘admin'(admin_id, email, domain_id, pass)
- ‘domain'(domain_id, name)
- ‘user’ (user_id, email, domain_id, pass)
Admin table:
+--------------------------------+
| admin_id | email | domain_id |
+--------------------------------+
| 1 | aaa | 2034 |
| 2 | bbb | 3034 |
| 3 | ccc | 2034 |
+--------------------------------+
User table
+--------------------------------+
| user_id | email | domain_id |
+--------------------------------+
| 11 | aaa | 2034 |
| 12 | bbb | 3034 |
| 13 | ccc | 2034 |
| 15 | ddd | 2034 |
| 16 | eee | 3034 |
+--------------------------------+
Domain table:
+-----------------------+
| domain_id | name |
+-----------------------+
| 2034 | aaa.com |
| 3034 | bbb.com |
+-----------------------+
Output:
+------------+
|ddd@aaa.com |
|eee@bbb.com |
+------------+
So i want records from user table which are not present in admin table.
Is there any way to this without NOT IN query?
Yes, using LEFT JOIN of user with admin.
If
idattribute in user and admin tables is used to decide if the two records belong to the same user, then your LEFT JOIN would be on this attribute, as follows:If
idattribute alone is not enough and you needdomain_idas well to decide that two records belong to the same user, thenEdit:
As per your update to the question, since email and domain are shared by both admin and user tables, you should LEFT JOIN these tables on those two columns: