Duplicate records in a column of a table
Hi,
Can someone tell me how to get the duplicate records in a column of a table
what is the sql query.
Can anyone pls give an example
Can someone tell me how to get the duplicate records in a column of a table select your_column, count(*)
from your_table
group by your_column
having count(*) > 1;
Similar Messages
-
Removing duplicates record form a column
I ran this query to populate a field with random numbers but it keeps populating with some duplicate records. Any idea how I can remove the duplicates?
UPDATE APRFIL
SET ALTATH = CONVERT(int, RAND(CHECKSUM(NEWID())) * 10000);Prashanth,
You are correct the update does create the non-dupes records, it just doesn't insert them into the ALTATH field. I verify by running the select altath from aprfil table and the results are not the same records display after the updates. I hope I am clear
enough and thanks for your efforts.
Can you give example of a case where it doesnt work? It may be that values in actual were not duplicates due to presence of some unprintable characters like space characters.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Duplicate records on formula column
I have a dataset that I am trying to modify to remove the duplicates based on the previous record.
ID Name Number of Days
1 Bob 2
1 Jim 2
2 Harry 8
3 John 10
4 Mary 5
4 Sue 5
4 Billy 5
I want to show the second Number of Days record to zero if the previous ID is the same. How do I do that in regular SQL and not PL/SQL loop? What function(s) could I use? I am putting this in Oracle Reports and the dataset should look like this:
ID Name Number of Days
1 Bob 2
1 Jim 0
2 Harry 8
3 John 10
4 Mary 5
4 Sue 0
4 Billy 0The actual table has many records and the real data
is taking the lowest ascending name. So if the
records are :
1 MARY 10
1 SUE 10
Then, it should print :
1 MARY 10
1 SUE 0how about this?
4 Mary 5
4 Sue 0
4 Billy 0
shouldn't be ?
4 Billy 5
4 Mary 0
4 Sue 0
then
SQL> with t as
2 (select 1 id, 'Bob' name, 2 num from dual union all
3 select 1, 'Jim', 2 from dual union all
4 select 2, 'Harry', 8 from dual union all
5 select 3, 'John', 10 from dual union all
6 select 4, 'Mary', 5 from dual union all
7 select 4, 'Sue', 5 from dual union all
8 select 4, 'Billy', 5 from dual)
9 select id,name,decode(id,prev_id,0,num) num
10 from
11 (select id,name,num,lag(id, 1, 0) OVER (partition by id ORDER BY id,name) prev_id
12 from t);
ID NAME NUM
1 Bob 2
1 Jim 0
2 Harry 8
3 John 10
4 Billy 5
4 Mary 0
4 Sue 0
7 rows selected.added solution
Message was edited by:
devmiral -
How to display records dynamically by columns of the table?
hi to all,
i'm trying to figure out quite a long time now. is it possible to populate html table with records via columns? (because most of us are familiar with rows up to the last record) i do have a pseudocode below:
print ('<table>');
while (!eof) {
if (cnt % 4 == 0)
// breakline w/c means let's have another row since
// we displayed the records 4x now so we need
// another row to continue
else
// continue column generation
cnt++
print ('</table>');
i don't know if this is quite clear... but i do hope you know what my goal is... i have an app that i need to display (like live.com in searching images) to display all the searched items (and then onmouseover it will get big some sort)... but since the records i have are the ff:
CREATE TABLE "ERA_DB"."PARTS"
( "PARTID" VARCHAR2(15 BYTE) NOT NULL ENABLE,
"PARTNAME" VARCHAR2(75 BYTE) NOT NULL ENABLE,
"RETAILPRICE" NUMBER NOT NULL ENABLE,
"COSTPRICE" NUMBER NOT NULL ENABLE,
"ACTIVE" NUMBER DEFAULT 1,
"CATEGORY" VARCHAR2(2 BYTE) DEFAULT 'NA',
"DESCRIPTION" VARCHAR2(255 BYTE),
"TYPE" NUMBER DEFAULT 1 NOT NULL ENABLE,
CONSTRAINT "PARTS_PK" PRIMARY KEY ("PARTID") ENABLE
i need to display like the ff:
partname
partid
image
description
price
these are inside a box w/ borders (the concept is like live.com in their image search)
thanks so much!This was written for pear::db but I think it should go pretty similar for ADODB.
$result = $db->query ("SELECT PRODUCT FROM INVENTORY WHERE COMPANY='$_SESSION[company]'");
while ($data1 = $result->fetchRow(DB_FETCHMODE_ASSOC))
$data2 = $result->fetchRow(DB_FETCHMODE_ASSOC);
$data3 = $result->fetchRow(DB_FETCHMODE_ASSOC);
$data4 = $result->fetchRow(DB_FETCHMODE_ASSOC);
$rows .= " <tr>\n";
$rows .= " <td width=150 align=right>".$data1[PRODUCT]."</td>\n";
$rows .= " <td width=150 align=right>".$data2[PRODUCT]."</td>\n";
$rows .= ' <td width=150 align=right>".$data3[PRODUCT]."</td>\n";
$rows .= " <td width=150 align=right>".$data4[PRODUCT]."</td>\n";
$rows .= " </td>\n";
$rows .= " </tr>\n";
} -
Delete duplicate records based on condition
Hi Friends,
I am scratching my head as how to select one record from a group of duplicate records based upon column condition.
Let's say I have a table with following data :
ID START_DATE END_DATE ITEM_ID MULT RETAIL | RETAIL / MULT
1 10/17/2008 1/1/2009 83 3 7 | 2.3333
2 10/17/2008 1/1/2009 83 2 4 | 2
3 10/17/2008 1/1/2009 83 2 4 | 2
4 10/31/2008 1/1/2009 89 3 6 | 2
5 10/31/2008 1/1/2009 89 4 10 | 2.5
6 10/31/2008 1/1/2009 89 4 10 | 2.5
7 10/31/2008 1/1/2009 89 6 6 | 1
8 10/17/2008 10/23/2008 124 3 6 | 2From the above records the rule to identify duplicates is based on START_DATE,+END_DATE+,+ITEM_ID+.
Hence the duplicate sets are {1,2,3} and {4,5,6,7}.
Now I want to keep one record from each duplicate set which has lowest value for retail/mult(retail divided by mult) and delete rest.
So from the above table data, for duplicate set {1,2,3}, the min(retail/mult) is 2. But records 2 & 3 have same value i.e. 2
In that case pick either of those records and delete the records 1,2 (or 3).
All this while it was pretty straight forward for which I was using the below delete statement.
DELETE FROM table_x a
WHERE ROWID >
(SELECT MIN (ROWID)
FROM table_x b
WHERE a.ID = b.ID
AND a.start_date = b.start_date
AND a.end_date = b.end_date
AND a.item_id = b.item_id);Due to sudden requirement changes I need to change my SQL.
So, experts please throw some light on how to get away from this hurdle.
Thanks,
Raj.Well, it was my mistake that I forgot to mention one more point in my earlier post.
Sentinel,
Your UPDATE perfectly works if I am updating only NEW_ID column.
But I have to update the STATUS_ID as well for these duplicate records.
ID START_DATE END_DATE ITEM_ID MULT RETAIL NEW_ID STATUS_ID | RETAIL / MULT
1 10/17/2008 1/1/2009 83 3 7 2 1 | 2.3333
2 10/17/2008 1/1/2009 83 2 4 | 2
3 10/17/2008 1/1/2009 83 2 4 2 1 | 2
4 10/31/2008 1/1/2009 89 3 6 7 1 | 2
5 10/31/2008 1/1/2009 89 4 10 7 1 | 2.5
6 10/31/2008 1/1/2009 89 4 10 7 1 | 2.5
7 10/31/2008 1/1/2009 89 6 6 | 1
8 10/17/2008 10/23/2008 124 3 6 | 2So if I have to update the status_id then there must be a where clause in the update statement.
WHERE ROW_NUM = 1
AND t2.id != t1.id
AND t2.START_DATE = t1.START_DATE
AND t2.END_DATE = t1.END_DATE
AND t2.ITEM_ID = t1.ITEM_IDInfact the entire where_ clause in the inner select statement must be in the update where clause, which makes it totally impossible as T2 is persistent only with in the first select statement.
Any thoughts please ?
I appreciate your efforts.
Definitely this is a very good learning curve. In all my experience I was always writing straight forward Update statements but not like this one. Very interesting.
Thanks,
Raj. -
SQL Query to retrieve one line from duplicate records
Hi
I have one table which contains duplicate records in multiple column but the difference is in one column which contains the value 0 or positive. The query i want is to retrieve only the line with the positive value for only the duplicated records.
here below a sample data for your reference:
CREATE TABLE TRANS
CALLTRANSTYPE NVARCHAR2(6),
ORIGANI NVARCHAR2(40),
TERMANI NVARCHAR2(40),
STARTTIME DATE,
STOPTIME DATE,
CELLID NVARCHAR2(10),
CONNECTSECONDS NUMBER,
SWITCHCALLCHARGE NUMBER
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:15:00','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:15:25','mm/dd/yyyy hh24:mi:ss'),null,25,0)
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:15:00','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:15:25','mm/dd/yyyy hh24:mi:ss'),null,25,18000)
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:18:03','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:18:20','mm/dd/yyyy hh24:mi:ss'),null,17,0)
The output i want to have is:
CALLTRANSTYPE ORIGANI TERMANI STARTTIME STOPTIME CELLID CONNECTSECONDS SWITCHCALLCHARGE
REC 555988801 222242850 05/15/2012 09:15:00 05/15/2012 09:15:25 25 18000
REC 555988801 222242850 05/15/2012 09:18:03 05/15/2012 09:18:20 17 0 Thank you.Hi ekh
this is the query i want to have, thank you for the help:
SQL> Select *from
select CALLTRANSTYPE,ORIGANI,TERMANI,STARTTIME,STOPTIME,CELLID,CONNECTSECONDS,SWITCHCALLCHARGE
,row_number() over( partition by STARTTIME ,STOPTIME order by SWITCHCALLCHARGE DESC ) rn from TRANS
where rn=1;
CALLTR ORIGANI TERMANI STARTTIME STOPTIME CELLID CONNECTSECONDS SWITCHCALLCHARGE RN
REC 555988801 222242850 15-MAY-12 15-MAY-12 25 18000 1
REC 555988801 222242850 15-MAY-12 15-MAY-12 17 0 1Regrads
Lucienot. -
Finding duplicate values in a column with different values in a different c
I'm finding duplicate values in a column of my table:
select ba.CLAIM_NUMBER from bsi_auto_vw ba
group by ba.CLAIM_NUMBER
having count(*) > 1;
How can I modify this query to find duplicate values in that column where I DON'T have duplicate values in a different specific column in that table (the column CLMT_NO in my case can't have duplicates.)?Well, you can use analytics assuming you don't mind full scanning the table.....
select
count(owner) over (partition by object_type),
count(object_type) over (partition by owner)
from all_objects;You just need to intelligently (i didn't here) find your "window" (partition clause) to sort the data over, then make use of that (the analytics would be in a nested SQL and you'd then evaluate it in outside).
Should be applicable if i understand what you're after.
If you post some sample data we can mock up a SQL statement for you (if what i tried to convey wasn't understandable). -
Duplicate record in Masterdata: Failure in Chain, Successful when manually
Hi all,
A daily load updates 0BPARTNER_ATTR from CRM.
Recently this load started to fail, with the following error message:
xx duplicate records found. xxxx recordings used in table /BI0/XBPARTNER
The data load through PSA, but there is no red record in the PSA.
After copying the PSA data to Excel for further analysis I concluded there are actually no duplicate in the PSA.
Also, the option 'Ignore double data records' in the infopackage is checked.
When I manually update from PSA the load is successful.
This started to happen about two weeks ago, and I didn't find an event which could have caused it.
Now it happens every two or three days, and each time the manual update is successful.
Any suggestions, anyone?
Thanks, Jan.Hi Jan,
Possibly you would have two requests in PSA and you would try to update the Data Target.
Delete all the requests in PSA, schedule once again to bring the data to PSA and update then into Data Target.
Thank you,
Arvind -
How to delete duplicate records in all tables of the database
I would like to be able to delete all duplicate records in all the tables of the database. Many of the tables have LONG columns.
Thanks.Hello
To delete duplicates from an individual table you can use a construct like:
DELETE FROM
table_a del_tab
WHERE
del_tab.ROWID <> (SELECT
MAX(dups_tab.ROWID)
FROM
table_a dups_tab
WHERE
dups_tab.col1 = del_tab.col1
AND
dups_tab.col2 = del_tab.col2
)You can then apply this to any table you want. The only differences will be the columns that you join on in the sub query. If you want to look for duplicated data in the long columns themselves, I'm pretty sure you're going to need to do some PL/SQL coding or maybe convert them to blobs or something.
HTH
David -
Identifying duplicate records in a table
I am trying to identify duplicate records in a table - well they are broadly duplicated but some of the fields are changed on each insert whilst others are always the same.
I can't work out the logic and it is driving me #$%$#^@ crazy !Here are a couple of other examples:
Method 1: -- Makes use of the uniqueness of Oracle ROWIDs to identify duplicates.
=========
To check for single column duplicates:
select rowid, deptno
from dept outer
where
outer.rowid >
(select min(rowid) from dept inner
where inner.deptno=outer.deptno)
order by deptno;
To check for multi-column (key) duplicates:
select rowid, deptno, dname
from dept outer
where
outer.rowid >
(select min(rowid) from dept inner
where inner.deptno| |inner.dname=outer.deptno| |outer.deptno)
order by deptno;
Method 2: -- Makes use of resultset groups to identify uniqueness
=========
To check for single column duplicates:
select rowid, deptno
from dept
where
deptno in
(select deptno from dept group by deptno having count(*) > 1)
order by deptno;
To check for multi-column (key) duplicates:
select rowid, deptno, dname
from dept
where
deptno| |dname in
(select deptno| |dname from dept group by deptno| |dname having count(*) > 1)
order by deptno;
null -
Avoiding duplicate records while inserting into the table
Hi
I tried the following insert statement , where i want to avoid the duplicate records while inserting itself
but giving me the errror like invalid identifier, though the column exists in the table
Please let me know Where i'm doing the mistake.
INSERT INTO t_map tm(sn_id,o_id,txt,typ,sn_time)
SELECT 100,
sk.obj_id,
sk.key_txt,
sk.obj_typ,
sysdate,
FROM S_KEY sk
WHERE sk.obj_typ = 'AY'
AND SYSDATE BETWEEN sk.start_date AND sk.end_date
AND sk.obj_id IN (100170,1001054)
and not exists (select 1
FROM t_map tm1 where tm1.O_ID=tm.o_id
and tm1.sn_id=tm.sn_id
and tm1.txt=tm.txt
and tm1.typ=tm.typ
and tm1.sn_time=tm.sn_time )Then
you have to join the table with alias tml where is that ?do you want like this?
INSERT INTO t_map tm(sn_id,o_id,txt,typ,sn_time)
SELECT 100,
sk.obj_id,
sk.key_txt,
sk.obj_typ,
sysdate,
FROM S_KEY sk
WHERE sk.obj_typ = 'AY'
AND SYSDATE BETWEEN sk.start_date AND sk.end_date
AND sk.obj_id IN (100170,1001054)
and not exists (select 1
FROM t_map tm where sk.obj_ID=tm.o_id
and 100=tm.sn_id
and sk.key_txt=tm.txt
and sk.obj_typ=tm.typ
and sysdate=tm.sn_time ) -
Counting duplicate records in a table
Hi,
I have to display duplicate records in a table,but the table name and column should be passed dynamically(In procedure). Please let me know the query for this.Try this one, is used to find the duplicate value from table
Type: I
SELECT * FROM employees e1 WHERE rowid> (SELECT min(rowid)
FROM employees e2 WHERE e1.department_id=e2.department_id);
Type: II
SELECT * FROM my_table t1 WHERE EXISTS (SELECT 'x' FROM my_table t2
WHERE t2.key_value1 = t1.key_value1
AND t2.key_value2 = t1.key_value2
AND t2.rowid > t1.rowid);
Type: III
SELECT count(*), empn FROM empmast_dum
GROUP BY empn HAVING count(*) >1 ORDER BY empn;
Type: IV
SELECT dep, name,net,RANK() OVER (PARTITION BY dep ORDER BY net) rank
FROM empmast_dump
WHERE dep=04;
Type: V
SELECT empn FROM empmast_dump
WHERE empn NOT IN(SELECT MIN(empn)
FROM empmast_dump GROUP BY NAME;
I have to display duplicate records in a
table,but the table name and column should be passed
dynamically(In procedure). Please let me know the
query for this.When you need to pass table name dynamically in your procedure ,
just enter table name as substitution variable or bind variable, if u want to know about
this, read here
venki
http://venki-hb.blogspot.com/2008/02/basic-sql-query-tips.html -
How to delete the duplicate records in a table without promary key
I have a table that contains around 1 million records and there is no promary key or auto number coulums. I need to delete the duplicate records from this table. what is the simple effective way to do this.
Please see this link:
Remove duplicate records ...
sqldevelop.wordpress.com -
How to make a particular record in a particular column in a table as a link
Hi All,
I have a table in which the data is getting populated from the response of the BAPI.
I have a column in this table which is not related to the BAPI response. I am binding the column with locally created attribute which is related to the custom controller also.
The name of this column is LINK. The records for this column is "click to view".
According to the requirement,I have two webservices which I am suppose to use in the same table.
So the "click to view" should be enbled for the records from one webservice and should be disabled for the other.
Now I have successfully added the column LINK and the record for it is also"click to view" as i have set it.But its not acting as a link.
So kindly help me out.Looking forward to you.
Regards
DKHi Dipendra,
You can dynamically change TableCellEditor as you want a LINK at one time and no LINK(i.e. TextView ) at other time.
You can get the handle for your table with IWDTable interface and then get handle for your table column with IWDTableColumn. Once you get these you can change the TableCellEditor for that column at runtime.
I would sugesst you to read <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/7f531207-0301-0010-5f9c-8652a3232ae0">this</a> document for further details on how to set TableCellEditor at runtime etc.
Hope this helps,
Regards,
Mausam -
Duplicate record with same primary key in Fact table
Hi all,
Can the fact table have duplicate record with same primary key . When i checked a cube i could see records with same primary key combination but the key figure values are different. My cube has 6 dimentions (Including Time,Unit and DP) and 2 key figures. So 6 fields combined to form the composite primary key of the fact table. When i checked the records in se16 i could see duplicate records with same primary key. Ther are no parallel loading happening for the cube.
BW system version is 3.1
Data base is : Oracle 10.2
I am not sure how is this possible.
Regards,
PMHi Krish,
I checked the datapacket dimention also. Both the record have same dimention id (141). Except the Keyfigure value there is no other change in the Fact table record. I know this is against the basic DBMS primary key rule. But i have records like this in the cube.
Can this situation arise when same records is there in different data packet of same request.
Thx,
PM
null
Maybe you are looking for
-
Does apple tv hook up to sony str k840p
DOes sonyreciver hook up to str k840p hookup to apple tv 2. I want to use the surround sound.
-
Issue with Posting Date in F.05 - Foreign Currency Revaluation
Hi All, We have a problem with the US-GAAP Foreign currency revaluation run which we're doing every month. Although the posting date is entered correctly (for this month as 30.09.2011), the postings that are created have the posting date of 31.07.201
-
I need to reinstall Dictionary and Calculator - Lion
I accidentally deleted Dictionary and Calculator with a third party app, and I'd like to get them back. After trying a few things, I decided to just reinstall Lion, but the OSX recovery mode -- restart with command-r, or with command+option+r doesn't
-
PDF rewriter: concatinate/merge pdfs
I read this well written article: http://cqblueprints.com/xwiki/bin/view/CQ+FAQ/How+can+I+configure+the+PDF+rewriter and was able to edit the file here: /libs/wcm/core/content/pdf/page2fo.xsl to convert my .html file to .pdf on the fly. But I have
-
May I know how to uninstall Zenmate, please?
May I know how to uninstall Zen Mate in Mac Book Pro, please?