why cant i wrap my head around this query?

  • 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

  • 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

  • that's excatly what i wanted to do!

    Thanks!

  • 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

  • G2-

    So does that actually create simulated tabnles doing the T2?

    Kind of like a self join?

    Anyways, thanks again!

  • 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