This query works fine:select t.doc, ISNULL(COUNT(t.clm), 0) as PendInPSC from(select max(juris_mvt_seq_num) as juris_mvt_seq_num, clm, ppclms, org_id, juris_mvt_typ From t2pendjuris j group by clm, clmssn,org_id, juris_mvt_typ)bleft join t2dibpend t on b.clm=t.clmwhere t.clm not in (select clm from people where completedt is null )and juris_mvt_typ='r'and org_id like'P%' group by t.doc, t.clm, t.ppclms, org_id
What I need help with is how to add this select statement to the above query:(select max(dib_mvt_seq_num) as dib_mvt_seq_num, clm from t2dibpend tgroup by clm) f
I tried to add it as such:select t.doc, ISNULL(COUNT(t.clm), 0) as PendInPSC from(select max(juris_mvt_seq_num) as juris_mvt_seq_num, clm, ppclms, org_id, juris_mvt_typ From t2pendjuris j group by clm)bjoin(select max(dib_mvt_seq_num) as dib_mvt_seq_num, clm from t2dibpend tgroup by clm) fleft join t2dibpend t on b.clm=t.clm and f.clm= t.clmwhere t.cossn not in (select clm from people where completedt is null )and juris_mvt_typ='r'and org_id like'P%' group by t.doc, t.clm, t.ppclms, org_id
But I got these errors where the above is bold:Incorrect syntax near the keyword 'where'Incorrect syntax near the keyword 'and'What am I doing wrong?