MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL Needed

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
eskaysem
Beginner


Joined: 31 Mar 2003
Posts: 29
Topics: 13

PostPosted: Mon Mar 31, 2003 2:12 pm    Post subject: SQL Needed Reply with quote

Hi,
Suppose I have one table T1, with no primary Keys defined.

Sno. Ano.
_______________

S1 A1
S1 A1
S2 A2
S2 A2
S2 A2
S1 A1
S3 A3

Now I have an option to run only one query...and my Output should be affeted on that physical Tbale and my o/p should be:

Sno. Ano.
________________

S1 A1
S2 A2
S3 A3

That means all the duplicates shuold be removed keeping one copy.

I need to do this in only one query.
_________________
Thanks!,
Santosh Kulkarni
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Mon Mar 31, 2003 2:23 pm    Post subject: Reply with quote

Santhosh,

Code:


SELECT DISTINCT SNO, ANO FROM TABLE
ORDER BY SNO,ANO


Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
eskaysem
Beginner


Joined: 31 Mar 2003
Posts: 29
Topics: 13

PostPosted: Mon Mar 31, 2003 2:33 pm    Post subject: Reply with quote

This will only select the Distinct rows. My requirement is to delete the rest of rows which are found to be duplicates.
_________________
Thanks!,
Santosh Kulkarni
Back to top
View user's profile Send private message
Himesh
CICS Forum Moderator
CICS Forum Moderator


Joined: 20 Dec 2002
Posts: 80
Topics: 21
Location: Chicago

PostPosted: Sat Apr 12, 2003 12:11 pm    Post subject: Reply with quote

Santosh,

You will not be able to achieve the desired result using "only" one query.

Why don't you unload the data using the query that Kolusu had suggested,
and then load the same back into the table with the REPLACE option, which will delete all the existing rows.

In this way you will still be using only one query....

regards,
Himesh
Back to top
View user's profile Send private message Yahoo Messenger
hari_uss
Beginner


Joined: 19 Dec 2002
Posts: 78
Topics: 6
Location: Trivandrum, India

PostPosted: Sun Apr 13, 2003 4:33 am    Post subject: Reply with quote

In Oracle,

Code:


DELETE FROM T1 WHERE ROWID NOT IN(
SELECT MIN(ROWID) FROM T1
GROUP BY SNO, ANO)



Read this also. You can figure out a way to do it in DB2.

-----
Hari.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group