Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > Oracle
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 2nd, 2004, 04:07 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
  #2 (permalink)  
Old December 31st, 2004, 05:11 AM
Authorized User
 
Join Date: Dec 2004
Location: , , India.
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

  #3 (permalink)  
Old January 3rd, 2005, 03:08 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
  #4 (permalink)  
Old January 31st, 2005, 02:05 PM
Registered User
 
Join Date: Jan 2005
Location: hyd, a.p, India.
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.