Home Forums Programming General need help with CASE statement and table joins RE: need help with CASE statement and table joins

  • I have another join question for you SQL pros. The query below produces the accurate result set, but I'm guessing the syntax isn't up to current standards. Should the first where clause (where p.personcode = o.personcode) be an inner join? Or a nested query? And if so, how would you write it? Thanks so much for your help -

    tbladdress contains addresscode, addresses

    tblperson contains personcode, names

    tblaccount contains account #, other stuff needed

    tblacctowneraddress contains personcode, addresscode and account #

    select distinct a.accountno, a.parcelno, p.privateflag, p.name1, p.name2, a.businessname,

    ad.address1, ad.address2, ad.city, ad.statecode, ad.zipcode, ad.province, ad.country, ad.postalcode

    from tbladdress ad

    inner join tblperson p

    on (p.personcode = ad.personcode)

    inner join tblacctowneraddress o

    on (o.addresscode = ad.addresscode)

    inner join tblacct a

    on (a.accountno = o.accountno)

    where p.personcode = o.personcode

    and a.acctstatuscode = 'A'

    and a.accountno not like 'P%'

    and p.privateflag != '1'

    and o.primaryownerflag = '1'

    and a.verend = '99999999999'

    and p.verend = '99999999999'

    and o.verend = '99999999999'

    and ad.verend = '99999999999'

    order by a.accountno;