one to many relationship in sql

  • Hi

    I have a different situation. I would like to find out one-many relationship in my tables.

    Here is the sample data in my tables.

    ReqNo Group Date

    1 Health 01/01/2011

    1 Sports 01/01/2011

    2 Health 02/01/2011

    3 Park 01/01/2011

    4 Road 03/01/2011

    4 Park 03/01/2011

    I am expecting below result.

    ReqNo

    1

    4

    Can anybody help me?

    Please let me know if you need any sample code.

    Thanks

    Anitha

  • Hi

    I solved the problem mysef by reading below topic.

    http://www.petefreitag.com/item/169.cfm

    Thanks

    Anitha

  • Hi Anitha,

    Please try below query

    with m

    as

    (

    select reqno, ROW_NUMBER() OVER(PARTITION BY reqno ORDER BY reqno) AS DuplicateCount

    from mygroup

    )

    select * from m where DuplicateCount=2

    Reagrds,

    Sanjay K. Gope

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

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