Joins

  • Hi people,

    I have this:

    # Table X #

    cod     desc

    1         Peter

    2         Jonh

    3         Mary

    # Table Y #

    cod

    1      Mat

    2      Ing

    # Table Z #

    cod_x      cod_y     

    1                         1

    1                         2

    --------------

    Using join:

    select x.desc,y.desc from x,y,z where x.cod=z.cod_x and y.cod=z.cod_y

    Paul       Mat

    Paul       Ing

    How can I do the result in the same line ?

    Paul       Mat      Ing

    thanks a lot..........

     

  • Do it in your front end application.

    If you have to do it in t-sql

    select x.desc,

    max(case when y.cod = 1 then y.desc else '' end) as [Mat],

    max(case when y.cod = 2 then y.desc else '' end) as [Ing]

    from x,y,z

    where x.cod=z.cod_x and y.cod=z.cod_y

    group by x.desc

  • Or do it client side. Presentaion layer is a much better place to do these things. Excel can do, Reporting Services can do. SL 2005 now offers a pivot function but overall it is simpler to do in the client than SQL and most times more efficient.

     

    Sorry just noticed KH said the same thing.

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

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