Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2004, 04:07 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default New Query (Urgent!!)

Hi All ,

Anyone help me to write the query :)

****************************
Id | AccountNo.|Status
****************************
1 | A10000 |Y
****************************
1 | A20000 |Null
****************************
1 | A30000 |Null
****************************
2 | B10000 |Null
****************************
2 | B20000 |Null
****************************
2 | B30000 |Null
****************************
3 | C30000 |Null
****************************
3 | C20000 |Null
****************************
3 | C10000 |Null
****************************
4 | D10000 |Null
****************************
5 | E10000 |Y

I want to retrieve (ID ,AccountNo.and Status)

Conditions-

1-->if with particular Id there is "Y" and "Null" i want to retrieve only "Y" records
(i.e in above case 1,A10000,Y)and (5,E10000,Y)

2-->if with particular Id there is no "Y" ,then i want to retrieve only first records with status "Null" records
(i.e in above case 2,B10000,Null) and (2,C30000,Null)Note here C3 comes before C1.

Depending on above table i want to write query that can return following table
****************************
Id | AccountNo.|Status
****************************
1 | A10000 |Y
****************************
2 | B10000 |Null
****************************
3 | C30000 |Null
****************************
4 | D10000 |Null
****************************
5 | E10000 |Y


Awaiting for your reply

Cheers :)

vinod
__________________
Cheers :)

vinod
 
Old December 31st, 2004, 05:11 AM
Authorized User
 
Join Date: Dec 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The below mentioned query,
select * from test_tab where (ID, NVL(Status, 'Z')||ACC_NO) in (
select ID, MIN(NVL(Status, 'Z')||ACC_NO) aa from test_tab group by ID);

Gives result as,

1 1 A10000 Y
2 2 B10000
3 3 C10000
4 4 D10000
5 5 E10000 Y

Now why it does not Give you C30000 (in place of C10000) is, because you will have to give a Orader by statement Before you say "retrieve only first records". Otherwise you cannot say which is the first row.

  Hope this will help you.

Sujit

 
Old January 3rd, 2005, 03:08 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hi Sujit,
Thanks i tried your query ,it help me alott!!!
I appreciate your help.


Cheers :)

vinod
 
Old January 31st, 2005, 02:05 PM
Registered User
 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

select * from test_tab where rowid in(select min(rowid)
from test_tab group by id);
i think you get the required answer .bye

thr





Similar Threads
Thread Thread Starter Forum Replies Last Post
plz reply 2m query,its very urgent.... preetham.sarojavenkatesh ASP.NET 1.x and 2.0 Application Design 2 August 1st, 2007 08:26 AM
Query About XSLT-Urgent harshalchoksi XSLT 6 February 23rd, 2007 06:43 AM
urgent query,,, please.....!!! SAAM C++ Programming 1 December 11th, 2006 08:22 AM
SQL query problem in Access - Urgent Kaustav Access 2 September 30th, 2005 11:39 PM
Urgent!! code for no match in Subform based query smercer Access 3 September 10th, 2004 11:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.