c# - SQL: select data which doesn't have relations in another table -


i'm writing c# application , using access .mdb. have table email messages , table message relations (each email msg can assigned several teams of workers).

i want to messages first table not assigned team - ie, either have no entries in second table or have empty entry. works ok empty entries doesn't return rows don't have assignment entry @ all.

i'm using following query:

select top 10 mails.*  mails inner join mailassignments on mails.msgid = mailassignments.msgid      (mails.msgid <= ?)     ,     (mails.msgid not in (select msgid mailassignments))     or (mailassignments.forteam null)     or (mailassignments.forteam = '') 

update:

i need use kind of join because on conditions query should return rows having relation in other table (eg. when wants display messages team , unassigned messages).

update:

ok, guess can make simplier deleting assignment second table don't need check empty assignments, ones don't exist @ all. still need show data assigned along data has not been assigned. , need build 1 query have different parameters changed :/

update / solution:

i did more adjustments left join did trick me! hint , help, guys!

this should enough:

select top 10 mails.*  mails      (mails.msgid <= ?)     ,     (mails.msgid not in (select msgid mailassignments)) 

reading description, seems tha may have rows in mailassignments related mails team has not assigned (the forteam column has empty string. not design in case, use this:

select top 10 mails.*  mails    left join       mailassignments on mails.msgid = mailassignments.msgid (mails.msgid <= ?)   , (  (mailassignments.forteam null)       or (mailassignments.forteam = '')       ) 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -