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:

  1. request logged in table 1 , 2 as:

table 1 :
message type: request send
id: 1

table 2 :
message type: request received
id: 1

  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) 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo