If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > atleast one occurence of the record

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-08, 11:54
ramanay ramanay is offline
Registered User
 
Join Date: Dec 2008
Posts: 10
atleast one occurence of the record

Hi,
I have 322 records of which 20 records have one column same which make them duplicate records for me so i want to get the total 302 records which means the records .

i cant use like select count(*),col_name from table_name
GROUP BY col_name
having count(*) >1; as it would eleminate the occurance of the record.

ANy suggestion please.

Thanks
-R
Reply With Quote
  #2 (permalink)  
Old 12-16-08, 12:00
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Is this an answer?
select DISTINCT col_name from table_name;
Reply With Quote
  #3 (permalink)  
Old 12-16-08, 12:46
ramanay ramanay is offline
Registered User
 
Join Date: Dec 2008
Posts: 10
No that doesn't solve my purpose as the entire record is not duplicate only some columns are and so it would be a distinct record anyways.
Reply With Quote
  #4 (permalink)  
Old 12-16-08, 13:15
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
I'm not well at English, so I couldn't understand your requirements fully.
Could you provide some sample data and required results?
Reply With Quote
  #5 (permalink)  
Old 12-16-08, 13:25
ramanay ramanay is offline
Registered User
 
Join Date: Dec 2008
Posts: 10
I have records this way..
cola colb colc
5710 123 abc00
5710 123 def00
5720 345 abc00
5720 345 def00


and i want to get

cola colb colc
5710 123 abc00
5720 345 abc00

and my preference is based on cola and i cant make any change to the data i just have execute privs.

Hope this makes it clear

Thanks
-R
Reply With Quote
  #6 (permalink)  
Old 12-16-08, 13:29
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by ramanay
I have records this way..
cola colb colc
5710 123 abc00
5710 123 def00
5720 345 abc00
5720 345 def00


and i want to get

cola colb colc
5710 123 abc00
5720 345 abc00

and my preference is based on cola and i cant make any change to the data i just have execute privs.

Hope this makes it clear
No it does not. Why do you choose "5710 123 abc00" and not "5710 123 def00"?
Reply With Quote
  #7 (permalink)  
Old 12-16-08, 13:41
ramanay ramanay is offline
Registered User
 
Join Date: Dec 2008
Posts: 10
when i have a single record based on cola it wud have abc00 or def00 for colc so its ok but when i have 2 records one with abc00 and one with def00 for the same value of cola it is supposed to be the one with abc00( and i just have these 2 values for colc )

Can i use like rowid and rowid+1 and chk the cola and retrieve the first value of cola.
I'm confused how to go ahead on this


Thanks
-R
Reply With Quote
  #8 (permalink)  
Old 12-16-08, 14:17
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Code:
select cola, colb, min(colc) from yourtable group by cola, colb
Since you did not post the actual requirements, you will have to adapt the above to your data yourself.

PS. Please refrain from using lolspeak on this board - some people find it not just annoying but disrespectful.
Reply With Quote
  #9 (permalink)  
Old 12-16-08, 16:58
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Nick is right (not only on the lolspeak). You need to do some sort of aggregation. The values in your column in question define the groups and in each group you have to figure out which record to choose for the result set.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #10 (permalink)  
Old 12-16-08, 17:37
ramanay ramanay is offline
Registered User
 
Join Date: Dec 2008
Posts: 10
I joined this forum just today..i dont know what lol speak is but i think its about the dummy data i provided..sorry if thats against the rules..thanks for your help

-R
Reply With Quote
  #11 (permalink)  
Old 12-16-08, 18:13
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
"lolspeak" is the "language" commonly used in text messaging, where you substitute abbreviations in place of the regular words, don't use punctuation marks or proper capitalization, e.g.

Quote:
when i have a single record based on cola it wud have
Quote:
Can i use like rowid and rowid+1 and chk the cola
It may be faster to type, which I doubt, but it's quite difficult to read.

Last edited by n_i; 12-16-08 at 18:17.
Reply With Quote
  #12 (permalink)  
Old 12-16-08, 22:11
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
To make your requirements clearer(for me), you can add more rows for your example.

For these rows of data.
cola colb colc
5710 123 abc00
5710 123 def00
5710 135 abc00
5710 135 aaa00
5720 345 abc00
5720 345 def00
5720 111 ghi00

What do you want to get?

cola colb colc
5710 123 abc00 -- this?
5710 135 aaa00 -- or this?, or both?
5720 ??? ?????

Last edited by tonkuma; 12-16-08 at 22:15.
Reply With Quote
  #13 (permalink)  
Old 12-17-08, 23:05
arlf arlf is offline
Registered User
 
Join Date: May 2006
Posts: 16
Try something like this:
(COLA is the col with duplicated values)
SELECT TBLX.COLA, TBLX.COLB, TBLX.COLC, ...
FROM ( SELECT TBL1.*, ROW_NUMBER() OVER () RID
FROM TBL1 ) TBLX
WHERE TBLX.RID = (SELECT MIN(B.RID) FROM TBLX A
WHERE A.COLA = TBLX.COLA)

Saludos, arlf.
Reply With Quote
  #14 (permalink)  
Old 12-18-08, 03:29
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Or a bit simpler, in case you want to see just one row per value of cola:
Code:
WITH t AS
(SELECT cola, MIN(colb) AS colb
 FROM   table_name
 GROUP BY cola)
SELECT t.cola, t.colb, MIN(x.colc)
FROM   t INNER JOIN table_name x ON t.cola = x.cola AND t.colb = x.colb
GROUP BY t.cola, t.colb
(See also Nick's post from Tuesday for a yet simpler solution, in case you want to see one row per (cola, colb) combination.)
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/

Last edited by Peter.Vanroose; 12-18-08 at 03:42.
Reply With Quote
Reply

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 On
Pingbacks are On
Refbacks are On