How to display Unique id' value record

  • Dear All,

    XYZ TABLE

    Name age id

    Sumanta 16 1

    Sagar 17 1

    Suresh 15 2

    Rakesk 18 3

    Pratap 11 3

    Sekhar 14 3

    How to write a query if id is given and its value is unique in the xyz table then its value will return else no value returns.

    For example SELECT * FROM XYZ WHERE ID=2

    Return value:: Suresh 15 2

    For example SELECT * FROM XYZ WHERE ID=3

    No return

    Please help me for the needful.

    Regards,

    Sumanta panda

  • Add this to your Where clause:

    and ID in (select id from XYZ group by id having count(*) = 1)

    - 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

  • Thanks a lot.It is working fine.

    Regards,

    Sumanta

  • 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

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

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