September 29, 2009 at 9:09 am
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
September 29, 2009 at 9:22 am
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
September 30, 2009 at 11:13 am
Thanks a lot.It is working fine.
Regards,
Sumanta
September 30, 2009 at 12:07 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
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply