I’m working on joining 3 tables.
table1.
grp_id | email_id
1 | 3
1 | 58
table2.
sam_msg_id | sam_subject
3 | Funnel
table3.
id | subject
58 | testing check
Desired Output:
id |grp_id|email_id|sam_subject|subject |
184|1 |3 |funnel | |
185|1 |58 | |testing check|
the query I tried:
SELECT table1.*, table2.sam_subject, table3.*
FROM table1
INNER JOIN table2
ON table2.sam_msg_id = table1.email_id
INNER JOIN table3
ON table3.id = table1.email_id
WHERE table1.grp_id = '1'
What I’m trying to do here is to get the list of subject and its id from table2 and table3 where the id is found at table1 under email_id.
When I tried doing it with one inner join only by checking only the data from table2 it was working.
I am not familiar in using inner joins thus I can’t really see what I’m doing wrong.
I am using MySQL.
Sounds like you need a
LEFT JOINBased on you edit, the following should give you the results you want:
See SQL Fiddle with Demo