January 9, 2007 at 1:48 am
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
January 9, 2007 at 2:04 am
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
January 9, 2007 at 2:20 am
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)
January 9, 2007 at 2:27 am
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 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy