Linq to SQL distinct join and group -


i've been struggling linq query... have following 2 tables: 1) emailrunheaders - columns: id, emailrunid, emailid 2) emailtrackers - columns: id, emailid

every day batch of emails sent. unique "emailrunid" assigned batch/group of emails , each email assigned "emailid". info stored in "emailheaders" table. so, each emailid in table unique, emailrunid appear more once..since there more 1 email in each "batch" or run.

when email opened, using http handler, open logged in emailtracker table...where particular emailid stored. since email opened more once, possible emailid appear more once in table.

i need total number of emails opened, without double counting emails opened more once, every email run.

this have far. nested query works fine..returning total number of emails opened each run, if there @ least 1 opened each run. tried wrapping in join return distinct emailrunids header table..but stuck..i don't know how emailrunid "ah1".

from arh1 in emailrunheaders.select(x => x.emailrunid).distinct() join eo in  (from et in emailtrackers join arh2 in emailrunheaders on et.emailid equals arh2.emailid.tostring() j1 j2 in j1.defaultifempty() group j2 j2.emailrunid g select new {runid = g.key, count = g.count()}) on arh1 equals eo.runid tg tg2 in tg.defaultifempty() select tg2 


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -