| |
|
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.
|
 |

12-16-08, 11:54
|
|
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
|
|

12-16-08, 12:00
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
Is this an answer?
select DISTINCT col_name from table_name;
|
|

12-16-08, 12:46
|
|
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.
|
|

12-16-08, 13:15
|
|
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?
|
|

12-16-08, 13:25
|
|
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
|
|

12-16-08, 13:29
|
|
:-)
|
|
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"?
|
|

12-16-08, 13:41
|
|
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
|
|

12-16-08, 14:17
|
|
:-)
|
|
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.
|
|

12-16-08, 16:58
|
|
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
|
|

12-16-08, 17:37
|
|
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
|
|

12-16-08, 18:13
|
|
:-)
|
|
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.
|

12-16-08, 22:11
|
|
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.
|

12-17-08, 23:05
|
|
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.
|
|

12-18-08, 03:29
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|