join 3 tbls

  • I have a case like this:

    table a - has one filed with statusID

    table b - has one filed with statusID

    c - status code tbl - statusID(int,4), status Decription (char, 20)

    When I want to pull the description for the statuses I have in "a" and "b" for a particular custID (they will be always different) I could use:

    select * from a left join b on a.pk_a = b.fk_a left join c on a.fk_c = c.pk_c left join c as d on b.fk_c = d.pk_c

    where a.custid = "xxx"

    But I think that there is more elegant way of doing that.

    Any suggestions?

    Thanks a lot.

    MJ

  • Try this

     

    select * from

     a

    left join

     b

    on

     a.pk_a = b.fk_a

    left join

     c

    on

     a.fk_c = c.pk_c OR

     b.fk_c = c.pk_c

    where

     a.custid = "xxx"

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply