mysql - left join - trying to find missing records in 2nd table when there is still similar record fitting match condition -
i have 2 tables
table 1
- message type
- id
table 2
- message type
- id
i want find missing records in table 2 when:
- request logged in table 1 , 2 as:
table 1 :
message type: request send
id: 1
table 2 :
message type: request received
id: 1
- then response send , logged in table 1.
table 1 :
message type: response send
id: 1
table 2 :
nothing
now join find missing responses in table 2:
select t1.id table1 t1 left join table2 t2 on t1.id=t2.id t2.id null , t2.messagetype<>'request received'
unfortunately 0 rows. guess because there t2 record matching id filer out messagetype condition. how can solve this?
a simple not exists
clause should sufficient:
select * table1 t1 not exists (select null table2 t2 t2.id = t1.id)