get slice data of query

  • Dear guys,

     For instance I have 3 tables with data like these :

    Table 1

    =======

    a

    b

    c

    d

    Table 2

    =======

    a

    b

    c

    Table 3

    =======

    b

    c

    How can I get the result like this (slice the 3 tables) :

    b

    c

    If I use union, it will return "a,b,c,d"

    since union combines all the data

    Thank you very much,

    alexia

     

  • Not quite sure what you mean by a 'slice'...

    But from the example, my guess is that you want a value if it exists in all three tables, otherwise not?

    You can do that with a simple three-way join.

    SELECT a.col1

    FROM   tbl1 a

    JOIN   tbl2 b

    ON     a.pk = b.pk

    JOIN   tbl3 c

    ON     a.pk = c.pk

    Is it something like that you want?

    /Kenneth

  • Just Try This One......

    declare @a table(alpha  char(2))

    declare @b-2 table(alpha1  char(2))

    Declare @C table(alpha2  char(3))

    insert into @a

    Select 'a'

    union

    select 'b'

    union

    select 'c'

    union

    select 'd'

    insert into @b-2

    Select 'a'

    union

    select 'b'

    union

    select 'c'

    insert into @C

    Select 'a'

    union

    select 'b'

    Select a.alpha from @a a, @b-2 b, @C c

    where a.alpha = b.alpha1 and a.alpha = c.alpha2

     

    Shashi Kant(MCA)

  • mmm I was thinking too hard...u're absolutely right...

    I thought there is a specific key syntax for slicing the data, like 'union' ....

    thank you very much for your answer

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

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