December 4, 2009 at 1:02 pm
Hi, anyone that can point me in the right direction would have my thanks!
I have a table...
feilds
-------
PK
FK1
BlnA
i need to build a query that returns all pk rows, grouped by FK1, where FK1 is alike and blna has both a true and false within the subset of FK1.
for example:
PKFK1BLNA
1100true
2100True
3200False
4200True
5200True
6300False
7300False
8400True
9500False
10600False
11600False
12600True
i would want to return whatever fields i want from PKs 3-5,10-12 grouped by FK1.
Any ideas? Thanks for helping out!
Thanks,
tril
December 4, 2009 at 1:22 pm
Will this do what you need?
select *
from dbo.MyTable
where BLNA = 'True'
and exists
(select *
from dbo.MyTable T2
where FK1 = MyTable.FK1
and BLNA = 'False')
or BLNA = 'False'
and exists
(select *
from dbo.MyTable T3
where FK1 = MyTable.FK1
and BLNA = 'True');
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
December 4, 2009 at 1:31 pm
that's excatly what i wanted to do!
Thanks!
December 4, 2009 at 1:54 pm
You're welcome.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
December 4, 2009 at 3:42 pm
G2-
So does that actually create simulated tabnles doing the T2?
Kind of like a self join?
Anyways, thanks again!
December 7, 2009 at 7:30 am
It's pretty much a special form of self-join. Not sure what you mean by "simulated tables".
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply