Retrieving duplicate values from a table
I have a table that has 80,000 rows. One column contains text identifiers as varchar2. There are almost all unique. A select count(distinct id) statement returns 79,980 rows. Is there a way to return only the remaining 20?
To know the unique values you can do this. but it would not return the rows, only the 20 or less duplicate values.
SELECT textColumn, count(*) as cnt_occurences
FROM yourTable
GROUP BY txtColumn
HAVING count(*) > 1;
Similar Messages
-
How to retrieve 2 values from a table in a LOV
Hi
I'm pretty new to APEX. I try to retrieve two values from a table using a LOV. I have a table named DEBIT with then columns SITE, NAME and KEY
I want to display NAME to the user in a list. When the user select an item from the list, I want to retrieve the data of the SITE and KEY column of this item in order to launch an SQL command based on this two values.
How to retrieve thes two values whant the user chooses an item from the list ?
I apologize for my english, being french.
Regards.
ChristianChristian,
From what I understood about your requirement, you want a 'select list with submit' which displays "NAME" and based on the value selected, you want to get the corresponding values for "SITE" and "KEY" from the table.
<b>Step 1: Create a select list with submit, say P1_MYSELECT </b><br><br>
Use something like this in the dynamic list of values for the select list: <br>
SELECT NAME display_value, NAME return_value
FROM DEBIT<br><br>
<b>Step 2: Create a page process of type PL/SQL block. Also create 2 hidden items P1_KEY and P1_SITE. </b><br><br>
In the PL/sQL, write something like:
DECLARE
v_key DEBIT.KEY%TYPE;
v_site DEBIT.SITE%TYPE;
CURSOR v_cur_myvals IS
SELECT KEY, SITE
FROM DEBIT
WHERE NAME = :P1_MYSELECT;
BEGIN
OPEN v_cur_myvals;
LOOP
FETCH v_cur_myvals
INTO v_key,v_site;
EXIT WHEN v_cur_myvals%NOTFOUND;
:P1_KEY := v_key;
:P1_SITE := v_site;
END LOOP;
CLOSE v_cur_myvals;
END; <br><br>
Then you can use these values for whatever purpose you need to.
Hope this helps. -
How to retrieve the values from a table if they differ in Unit of Measure
How to retrieve the values from a table if they differ in Unit of Measure?
If no data is read
- Insure that you use internal code in SELECT statement, check via SE16 desactivating conversion exit on table T006A. ([ref|http://help.sap.com/saphelp_nw70/helpdata/en/2a/fa0122493111d182b70000e829fbfe/frameset.htm])
If no quanity in result internal table
- There is no adqntp field in the internal table, so no quantity is copied in itab ([ref|http://help.sap.com /abapdocu_70/en/ABAPINTO_CLAUSE.htm#&ABAP_ALTERNATIVE_1@1@]).
- - Remove the CORRESPONDING, so quantity will fill the first field adqntp1. ([ref|http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_WA.htm])
- - Then loop at the internal table and move the quantity when necessary to the 2 other fields.
* Fill the internal table
SELECT msehi adqntp
INTO TABLE internal table
FROM lipso2
WHERE vbeln = wrk_doc1
AND msehi IN ('KL','K15','MT').
* If required move the read quantity in the appropriate column.
LOOP AT internal_table ASSIGNING <fs>.
CASE <fs>-msehi.
WHEN 'K15'.
<fs>-adqnt2 = <fs>-adqnt1.
CLEAR <fs>-adqnt1.
WHEN 'MT'.
<fs>-adqnt3 = <fs>-adqnt1.
CLEAR <fs>-adqnt1.
ENDCASE.
ENDLOOP.
- You could also create another table with only fields msehi and adqntp and then collect ([ref|http://help.sap.com/abapdocu_70/en/ABAPCOLLECT.htm]) the data to another table.
Regards,
Raymond -
Retrieving Multiple Values from a table
Dear Experts,
Can anyone let me know how to retrieve multiple rows from a table using Oracle BPEL Database Adapter and assign it to a output variable?
Regards,
Pradeep.If the input XML Record is as follows
Input xmlRecord:
<EmployeeCollection>
<Employee>
<id>10</id>
<lastName>Smith</lastName>
</Employee>
<Employee>
<id>20</id>
<lastName>Ram</lastName>
</Employee>
</EmployeeCollection>
I'm getting the following output when used with either queryByExample or normal SELECT option with a WHERE condition
<EmployeeCollection>
<Employee>
<id>10</id>
<lastName>Smith</lastName>
</Employee>
</EmployeeCollection>
Instead of all the records in the Employee table which meet the where condition?
I NEED OUTPUT AS FOLLOWS:
<EmployeeCollection>
<Employee>
<id>10</id>
<lastName>Smith</lastName>
</Employee>
<Employee>
<id>20</id>
<lastName>Ram</lastName>
</Employee>
</EmployeeCollection>
I'm using Transformation with for-each option
Can some one help it is very urgent.
Thanks & Regards,
Murali Vikrala -
Delete duplicate values from a table
Hi All
I have a table like this
table:
id name plan code
1 sam normal 5
1 sam normal 6
1 sam special 5
1 sam Special 6I need to delete data in such a way that one entry with normal and one entry with special plan should remain and should be with different code. Does not matter whether normal stays with 5 or 6 code.
Can anyone tell me how to do the same? I tried with rowid but it deletes either both normal or both special or returns same code for normal and special.It is not that trivial, if I correctly understand your reqs. If there are as many plans as thare are codes and you have a row for each combination:
SQL> select *
2 from tbl
3 /
ID NAM PLAN CODE
1 sam normal 5
1 sam normal 6
1 sam special 5
1 sam special 6
SQL> delete tbl
2 where rowid not in (
3 with t as (
4 select rowid rid,
5 row_number() over(partition by id,name,code order by plan) plan_rn,
6 row_number() over(partition by id,name,plan order by code) code_rn
7 from tbl
8 )
9 select rid
10 from t
11 where plan_rn = code_rn
12 )
13 /
2 rows deleted.
SQL> select *
2 from tbl
3 /
ID NAM PLAN CODE
1 sam normal 5
1 sam special 6
SQL> SY. -
How to retrieve the values from PL/SQL table types.
Hi Every one,
I have the following procedure:
DECLARE
TYPE t1 IS TABLE OF emp%ROWTYPE
INDEX BY BINARY_INTEGER;
t t1;
BEGIN
SELECT *
BULK COLLECT INTO t
FROM emp;
END;
This procedure works perfectly fine to store the rows of employee in a table type. I am not able to retrieve the values from Pl/SQL table and display it using dbms_output.put_line command.
Can anybody help me please!!!!!
Thanks
Ahmed.You mean, you can't add this
for i in t.first..t.last loop
dbms_output.put_line(t(i).empno||' '||t(i).ename||' '||t(i).job);
end loop;or you can't add this
set serveroutput onor maybe, you are working in third party application where dbms_output is not applicable at all?
You see, not able like very similar it is not working - both are too vague...
Best regards
Maxim -
Retrieving values from a table
Hi all,
I need to retrieve values from CSKS-KOSTL for values containing the pattern entered by the user. For example, if the user enters 1, need to retrieve all the KOSTL values starting with 1. But when i write a SELECT statement mentioning where kostl in '1', it is ignoring all the values like (0000001, 00001034, 0012334, and others). Only values starting with 1 is only retrieved as this is a character field and due to conversion routine, zeroes are prefixed while storing in the database.
Could any one let me know how to retrieve the values from the database in this situation?If you want to use IN operator in your where clause then you should define a range variable(R_KOSTL) which refers to CSKS=KOSTL and populate the range as below
R_KOSTL-SIGN = 'I'.
R_KOSTL-OPTION = 'CP'.
R_KOSTL-LOW = '1*'.
APPEND R_KOSTL.
and then write your select statement as .... WHERE kostl IN r_kostl.
The approach suggested by Amit should also work fine.
Thanks
Kiran -
Can retrieve value from one table, but not the other (exception thrown)
Hi
I hope some friendly soul can help me out here. I have a local Access database file. I am able to get a value from all tables except for one, which throws this error: "System.NullReferenceException:
Object reference has not been specified to an object".
The rather simple lines of code when working is this:
Dim email As Object
value = MyDataSet.Tables("Table")(0)(1).ToString
Msgbox(email)
However, when simply changing from "Table" to "AnotherTable", the exception is thrown. I
have seriously no idea why. I've made sure the datatypes are the same and that the values are not NULL.
What gives?Hello,
Going with your last reply, you should be accessing data via the strong typed classes that get generated.
Example using Microsoft Northwind database accessing the customers table in a MS-Access database. Note the check for Rows, we could even go farther if we are questioning issue with the data via try-catch statements writing errors to the IDE Output window.
I would highly recommend never referencing rows without first checking if there are rows and secondly never reference columns by ordinal index, always use the column name. One example with ordinal positioning, suppose someone did SomeDataTable.Columns("SomeColName").SetOrdinal(3)
and you expect the ordinal position to be 1 ? things will crash-n-burn. Food for thought :-)
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.CustomersTableAdapter.Fill(Me.MainDataSet.Customers)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If MainDataSet.Customers.Rows IsNot Nothing Then
Dim FirstCompanyName As String = MainDataSet.Customers.FirstOrDefault.CompanyName
MessageBox.Show(FirstCompanyName)
Else
MessageBox.Show("No rows in customer table")
End If
End Sub
End Class
In this case we get the first record from below in Button1 Click
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. -
Removing duplicate values from selectOneChoice bound to List Iterator
I'm trying to remove duplicate values from a selectOneChoice that i have. The component binds back to a List Iterator on the pageDefinition.
I have a table on a JSF page with 5 columns; the table is bound to a method iterator on the pageDef. Then above the table, there are 5 separate selectOneChoice components each one of which is bound to the result set of the table's iterator. So this means that each selectOneChoice only contains vales corresponding to the columns in the table which it represents.
The selectOneChoice components are part of a search facility and allow the user to select values from them and restrict the results that are returned. The concept is fine and i works. However if i have repeating values in the selectOneChoice (which is inevitable given its bound to the table column result set), then i need to remove them. I can remove null values or empty strings using expression language in the rendered attribute as shown:
<af:forEach var="item"
items="#{bindings.XXXX.items}">
<af:selectItem label="#{item.label}" value="#{item.label}"
rendered="#{item.label != ''}"/>
</af:forEach>
But i dont know how i can remove duplicate values easily. I know i can programatically do it in a backing bean etc.... but i want to know if there is perhaps some EL that might do it or another setting that ADF gives which can overcome this.
Any help would be appreciated.
Kind RegardsHi,
It'll be little difficult removing duplicates and keeping the context as it is with exixting standard functions. Removing duplicates irrespective of context changes, we can do with available functions. Please try with this UDF code which may help you...
source>sort>UDF-->Target
execution type of UDF is Allvalues of a context.
public void UDF(String[] var1, ResultList result, Container container) throws StreamTransformationException{
ArrayList aList = new ArrayList();
aList.add(var1(0));
result.addValue(var1(0));
for(int i=1; i<var1.length; i++){
if(aList.contains(var1(i)))
continue;
else{
aList.add(var1(i));
result.addValue(var1(i));
Regards,
Priyanka -
How to retrieve multiple values from a DB Adapter to a Web Service
Hello,
I'm creating a login WS that receives the username and password and returns the user status, full name and a set of permissions (the number of permissions varies among users).
In order to do that i've created a DBAdapter that is calling a PL/SQL procedure. This DBAdapter is connected to the login Web Service through a mediator.
I have two problems:
1 - I don't know the type of variable that the PL\SQL procedure should return. Like I said I need to retrieve an undefined number of values from a table (user permissions). How can I do this inside a PL\SQL procedure? What kind of structure should i return?
2 - How can i assign a multiple value variable (the permission variable) in the mediator? Is the mediator going to identify that this is variable is multiple valued and add automatically a for-each statement?
The Oracle DB version im using is the 11.1.0.7.0 and the Oracle SOA Suite 11.1.1.3.0.
Thanks in advance,
PauloHey guys,
thanks for your help.
I've created a userdefined type and sucessfully retrievied from the PL\SQL procedure multiple values. I have also mapped this values with the web service.
Even though everything's working fine i would like to understand if it is also possible to use the XMLType to return these values. I ask this cause I don't no if by returning a XMLType i can explicitly map the XML elements inside the mediator component.
If possible what are the main advantages/disavantages between using XMLType and Userdefined Types?
Paulo. -
How to get input text values from adf table - Urgent
Hi Friends,
This is my requirement. I designed customized master - detail - detail page. I customized the page in below format.
1. Master Data Field (Input text,etc) .
2. Detail in table format ( Rows are mapped to child table) and i given two buttons for to create row and delete row. I designed the table based on the example provided in forum for to create customized table. The input text component is mapped to the rows.
Now i want to retrieve all the data's entered in the rows. The table is mapped to child table. When i read the values from the table its showing null.
If any one faced this problem and fixed it, please send me the solution.
Thanks & Regards
VBDid you look into the valueChangeEvent?
It has oldValue and newValue attributes.
public void SaveMaterial(ValueChangeEvent valueChangeEvent) {
Object oldVal = valueChangeEvent.getOldValue();
Object newVal = valueChangeEvent.getNewValue();
// check if you see what you are looking for.....
getSelectedRow();
SaveMaterial(material);
}Timo -
How to delete the duplicate data from PSA Table
Dear All,
How to delete the duplicate data from PSA Table, I have the purchase cube and I am getting the data from Item data source.
In PSA table, I found the some cancellation records for that particular records quantity would be negative for the same record value would be positive.
Due to this reason the quantity is updated to target but the values would summarized and got the summarized value of all normal and cancellation .
Please let me know the solution how to delete the data while updating to the target.
Thanks
Regards,
SaiHi,
in deleting the records in PSA table difficult and how many you will the delete.
you can achieve the different ways.
1. creating the DSO maintain the some key fields it will overwrite the based on key fields.
2. you can write the ABAP logic deleting the duplicate records at info package level check with the your ABAPer.
3.you can restrict the cancellation records at query level.
Thanks,
Phani. -
Deleting rows from table based on value from other table
Hello Members,
I am struck to solve the issue said below using query. Would appreciate any suggestions...
I have two tables having same structures. I want to delete the rows from TableA ( master table ) with the values from TableB ( subset of TableA). The idea is to remove the duplicate values from tableA. The data to be removed are present in TableB. Catch here is TableB holds one row less than TableA, for example
Table A
Name Value
Test 1
Test 1
Test 1
Hello 2
Good 3
TableB
Name Value
Test 1
Test 1
The goal here is to remove the two entries from TableB ('Test') from TableA, finally leaving TableA as
Table A
Name Value
Test 1
Hello 2
Good 3
I tried below queries
1. delete from TestA a where rowid = any (select rowid from TESTA b where b.Name = a.Name and a.Name in ( select Name from TestB ));
Any suggestions..
We need TableB. The problem I mentioned above is part of process. TableB contains the duplicate values which should be deleted from TableA. So that we know what all values we have deleted from TableA. On deleted TableA if I later insert the value from TableB I should be getting the original TableA...
Thanks in advancedrop table table_a;
drop table table_b;
create table table_b as
select 'Test' name, 1 value from dual union all
select 'Test' ,1 from dual;
create table table_a as
select 'Test' name, 1 value from dual union all
select 'Test' ,1 from dual union all
select 'Test' ,1 from dual union all
select 'Hello' ,2 from dual union all
select 'Good', 3 from dual;
/* Formatted on 11/23/2011 1:53:12 PM (QP5 v5.149.1003.31008) */
DELETE FROM table_a
WHERE ROWID IN (SELECT rid
FROM (SELECT ROWID rid,
ROW_NUMBER ()
OVER (PARTITION BY name, VALUE
ORDER BY NULL)
rn
FROM table_a a
WHERE EXISTS
(SELECT 1
FROM table_b b
WHERE a.name = b.name
AND a.VALUE = b.VALUE))
WHERE rn > 1);
select * from table_a
NAME VALUE
Test 1
Hello 2
Good 3Edited by: pollywog on Nov 23, 2011 1:55 PM -
How to avoid duplicates values from alvgird see below code
how to avoid duplicates values from alvgird see below code
in below query docno no is repeated again and again
how i can avoid duplication in this query.
select * into corresponding fields of table itab
from J_1IEXCHDR
inner join J_1IEXCDTL
on J_1IEXCDTLlifnr = J_1IEXCHDRlifnr
where J_1IEXCHDr~status = 'P'.Hi Laxman,
after that select statement
select * into corresponding fields of table itab
from J_1IEXCHDR
inner join J_1IEXCDTL
on J_1IEXCDTLlifnr = J_1IEXCHDRlifnr
where J_1IEXCHDr~status = 'P'.
<b>if sy-subrc = 0.
delete adjucent duplicates from itab comparing <field name of itab internal table>
endif.</b>
this will delete your duplicate entries.once you done with this call the alv FM.
<b> call function 'REUSE_ALV_GRID_DISPLAY'</b>
exporting
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
i_callback_program = v_repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'IT_USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
i_grid_title = 'Purchase Order Details'
I_GRID_SETTINGS = I_GRID_SETTINGS
is_layout = wa_layout
it_fieldcat = it_fieldcat
IT_EXCLUDING = IT_EXCLUDING
IT_SPECIAL_GROUPS = IT_SPECIAL_GROUPS
it_sort = it_sort
IT_FILTER = IT_FILTER
IS_SEL_HIDE = IS_SEL_HIDE
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT = IS_VARIANT
it_events = it_event
IT_EVENT_EXIT = IT_EVENT_EXIT
IS_PRINT = IS_PRINT
IS_REPREP_ID = IS_REPREP_ID
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_HTML_HEIGHT_TOP = 0
I_HTML_HEIGHT_END = 0
IT_ALV_GRAPHICS = IT_ALV_GRAPHICS
IT_HYPERLINK = IT_HYPERLINK
IT_ADD_FIELDCAT = IT_ADD_FIELDCAT
IT_EXCEPT_QINFO = IT_EXCEPT_QINFO
IR_SALV_FULLSCREEN_ADAPTER = IR_SALV_FULLSCREEN_ADAPTER
IMPORTING
E_EXIT_CAUSED_BY_CALLER = E_EXIT_CAUSED_BY_CALLER
ES_EXIT_CAUSED_BY_USER = ES_EXIT_CAUSED_BY_USER
tables
<b> t_outtab = ITAB</b>
exceptions
program_error = 1
others = 2
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
Thanks
Vikranth Khimavath -
Need to remove duplicate rows from a table
Hi Gurus ,
I am using oracle 11.2.0.3 .
SQL> desc osstage.S_EVT_ACT_X;
Name Null? Type
ROW_ID NOT NULL VARCHAR2(15 CHAR)
LAST_UPD NOT NULL DATE
PAR_ROW_ID NOT NULL VARCHAR2(15 CHAR)
ATTRIB_17 NUMBER(22,7)
ATTRIB_26 DATE
ATTRIB_02 VARCHAR2(100 CHAR)
PROCESS_TIMESTAMP TIMESTAMP(6);
now when i give the below command it gives the error as someone has disabled the constraint accidently .
alter table s_evt_act_x enable constraint S_EVT_ACT_X_P1;
Error starting at line 3 in command:
alter table s_evt_act_x enable constraint S_EVT_ACT_X_P1
Error report:
SQL Error: ORA-02437: cannot validate (OSSTAGE.S_EVT_ACT_X_P1) - primary key violated
02437. 00000 - "cannot validate (%s.%s) - primary key violated"
*Cause: attempted to validate a primary key with duplicate values or null
values.
*Action: remove the duplicates and null values before enabling a primary
key.
Can you please guide me with this issue .Please refer
Script: Deleting Duplicate Rows from a Table (Doc ID 31413.1)
How to Find or Delete Duplicate Rows in a Table (Doc ID 1004425.6)
Maybe you are looking for
-
How Can I Display the Name of iPhoto Library?
I manage a huge number of images so I keeep them in their own iPhoto libraries. In order to change libraries, I have to rename the one I have just left and then restart iPhoto. I have looked for years but cannot find a way for iPhoto to display the n
-
Can I cut a file from a folder & copy it to another without leaving ori
Hi Can I cut a file form a folder and copy it into another folder without leaving the original in the 1st folder? I know I can copy it across. but I dont want to have to keep going back and deleting the original? Thanks
-
External display recognised, but no image
I have attached my MBP to an external monitor. Yosemite does recognise that there is an external monitor connected and it even knows it is a Samsung. But the screen stays black. The internal monitor screen keeps working just fine. In the display opti
-
Error While creating Third Party order in VA01
HI am trying to create Third Party order in VA01 in my sand box with material ( BANS item category Group) getting error NOT POSSIBLE TO DETERIMINE A CONSUMPTION ACCOUNT in OBYC GBB i tried to do some setting in VAX , VBR with valuation class 0001
-
[ ? ] Targetting function inside imported SWF
Hi, Is it possible to target function that's inside imported (or Loaded) swf file? I want to load external swf file into my fla project file, and then with a press of a button (for example) trigger a function that's inside that imported (or Loaded) s