Query to find out 2 columns duplicate records
hi
how can i find out duplicate records from a table with 2columns duplicated
eg: emp_id, book_id duplicated together
emp_id book_id
001 A
001 A
001 B
in this case query should return ( emp_id: 001 , book_id: A ) because these are duplicated together
SQL> with t as
2 (
3 select 1 a,'A' b from dual
4 union all
5 select 1,'A' from dual
6 union all
7 select 1,'B' from dual
8 )
9 select distinct a,b
10 from (
11 select t.*,count(1) over (partition by a,b order by a) cnt
12 from t)
13 where cnt > 1
14 /
A B
1 A
SQL> with t as
2 (
3 select 1 a,'A' b from dual
4 union all
5 select 1,'A' from dual
6 union all
7 select 1,'B' from dual
8 )
9 select a,b
10 from t
11 group by a,b
12 having count(*) > 1
13 /
A B
1 A
Similar Messages
-
How find out the duplicate value from each columns.
I have below four columns,
How can i find out the duplicate value from each columns.
with All_files as (
select '1000' as INVOICE,'2000' AS DELIVERYNOTE,'3000' CANDELINVOICE,'4000' CANDELIVERYNOTE from dual union all
select '5000','6000','7000','8000' from dual union all
select '9000','1000','1100','1200' from dual union all
select '1200','3400','6700','8790' from dual union all
select '1000','2000','3000','9000' from dual union all
select '1230','2340','3450','4560' from dual
SELECT * FROM All_files
Output should be as per below.
1000 2000 3000 4000
9000 1000 1100 1200
1200 3400 6700 8790
1000 2000 3000 9000
Required to check uniqueness in cross columns.
Thanks.Try this (sorry about the formatting)...
WITH all_files AS (SELECT '1000' AS INVOICE,
'2000' AS DELIVERYNOTE,
'3000' CANDELINVOICE,
'4000' CANDELIVERYNOTE
FROM DUAL
UNION ALL
SELECT '5000',
'6000',
'7000',
'8000'
FROM DUAL
UNION ALL
SELECT '9000',
'1000',
'1100',
'1200'
FROM DUAL
UNION ALL
SELECT '1200',
'3400',
'6700',
'8790'
FROM DUAL
UNION ALL
SELECT '1000',
'2000',
'3000',
'9000'
FROM DUAL
UNION ALL
SELECT '1230',
'2340',
'3450',
'4560'
FROM DUAL),
t_base
AS (SELECT invoice
|| ','
|| deliverynote
|| ','
|| candelinvoice
|| ','
|| candeliverynote
str
FROM all_files),
t_str
AS (SELECT str || ',' AS str,
(LENGTH (str) - LENGTH (REPLACE (str, ','))) + 1
AS no_of_elements
FROM t_base),
t_n_rows
AS ( SELECT LEVEL AS i
FROM DUAL
CONNECT BY LEVEL <=
( SELECT SUM (no_of_elements) FROM t_str)),
t_build AS (SELECT t_str.str,
nt.i AS element_no,
INSTR (t_str.str,
DECODE (nt.i, 1, 0, 1),
DECODE (nt.i, 1, 1, nt.i - 1))
+ 1
AS start_pos,
INSTR (t_str.str,
1,
DECODE (nt.i, 1, 1, nt.i))
AS next_pos
FROM t_str
JOIN
t_n_rows nt
ON nt.i <= t_str.no_of_elements),
t_build2
AS (SELECT RTRIM (str, ',') AS original_string,
SUBSTR (str, start_pos, (next_pos - start_pos))
AS single_element,
element_no
FROM t_build),
t_build3
AS (SELECT single_element,
COUNT( * )
OVER (PARTITION BY single_element
ORDER BY single_element)
ele_count
FROM t_build2)
SELECT DISTINCT INVOICE,
DELIVERYNOTE,
CANDELINVOICE,
CANDELIVERYNOTE
FROM all_files, t_build3
WHERE ele_count > 1
AND ( INVOICE = single_element
OR DELIVERYNOTE = single_element
OR CANDELINVOICE = single_element
OR CANDELIVERYNOTE = single_element)I think this will be faster than the previous solution?
Cheers
Ben
Edited by: Munky on Feb 17, 2011 2:11 PM - "I think this will be faster than the previous solution?", nope - it's not :( -
Hi ,
How to find out the latest Record in per_all_people_f and per_all_assignments_f
Requirement : Need to find out the latest record in per_all_people_f and per_all_assignments_f to update the attribute column with pre defined value . Its not possible to track only with person_id / assignment_id and effective end date
SELECT pp_id
FROM (SELECT app.person_id pp_id,
asf.*
FROM apps.per_all_people_f app,
apps.per_all_assignments_f asf
WHERE --app.person_id=123568 and
asf.person_id = app.person_id AND
app.effective_end_date = to_date('31-dec-4712') AND
asf.effective_end_date = to_date('31-dec-4712')
GROUP BY app.person_id)
HAVING COUNT(pp_id) > 1
GROUP BY pp_id
This query also returns more than 1 value for person_id .
It would be great if you put comment on this .. Thanks in advance ,
AryaI am getting more records with asf.primary_flag='Y' . If you give ur mail id , i will send the sample data
ASSIGNMENT_ID EFFECTIVE_START_DATE EFFECTIVE_END_DATE BUSINESS_GROUP_ID RECRUITER_ID GRADE_ID POSITION_ID JOB_ID ASSIGNMENT_STATUS_TYPE_ID PAYROLL_ID LOCATION_ID PERSON_REFERRED_BY_ID SUPERVISOR_ID SPECIAL_CEILING_STEP_ID PERSON_ID RECRUITMENT_ACTIVITY_ID SOURCE_ORGANIZATION_ID ORGANIZATION_ID PEOPLE_GROUP_ID SOFT_CODING_KEYFLEX_ID VACANCY_ID PAY_BASIS_ID ASSIGNMENT_SEQUENCE ASSIGNMENT_TYPE PRIMARY_FLAG APPLICATION_ID ASSIGNMENT_NUMBER CHANGE_REASON COMMENT_ID DATE_PROBATION_END DEFAULT_CODE_COMB_ID EMPLOYMENT_CATEGORY FREQUENCY INTERNAL_ADDRESS_LINE MANAGER_FLAG NORMAL_HOURS PERF_REVIEW_PERIOD PERF_REVIEW_PERIOD_FREQUENCY PERIOD_OF_SERVICE_ID PROBATION_PERIOD PROBATION_UNIT SAL_REVIEW_PERIOD SAL_REVIEW_PERIOD_FREQUENCY SET_OF_BOOKS_ID SOURCE_TYPE TIME_NORMAL_FINISH TIME_NORMAL_START BARGAINING_UNIT_CODE LABOUR_UNION_MEMBER_FLAG HOURLY_SALARIED_CODE REQUEST_ID PROGRAM_APPLICATION_ID PROGRAM_ID PROGRAM_UPDATE_DATE ASS_ATTRIBUTE_CATEGORY ASS_ATTRIBUTE1 ASS_ATTRIBUTE2 ASS_ATTRIBUTE3 ASS_ATTRIBUTE4 ASS_ATTRIBUTE5 ASS_ATTRIBUTE6 ASS_ATTRIBUTE7 ASS_ATTRIBUTE8 ASS_ATTRIBUTE9 ASS_ATTRIBUTE10 ASS_ATTRIBUTE11 ASS_ATTRIBUTE12 ASS_ATTRIBUTE13 ASS_ATTRIBUTE14 ASS_ATTRIBUTE15 ASS_ATTRIBUTE16 ASS_ATTRIBUTE17 ASS_ATTRIBUTE18 ASS_ATTRIBUTE19 ASS_ATTRIBUTE20 ASS_ATTRIBUTE21 ASS_ATTRIBUTE22 ASS_ATTRIBUTE23 ASS_ATTRIBUTE24 ASS_ATTRIBUTE25 ASS_ATTRIBUTE26 ASS_ATTRIBUTE27 ASS_ATTRIBUTE28 ASS_ATTRIBUTE29 ASS_ATTRIBUTE30 LAST_UPDATE_DATE LAST_UPDATED_BY LAST_UPDATE_LOGIN CREATED_BY CREATION_DATE TITLE OBJECT_VERSION_NUMBER
931510 7-Nov-08 31-Dec-12 122 (null) (null) (null) 3978 1 (null) 14402 (null) 220150 (null) 734956 (null) (null) 476 (null) (null) (null) (null) 2 E Y (null) 100035417-2 (null) (null) (null) 45948739 (null) (null) (null) (null) (null) (null) (null) 868007 (null) (null) (null) (null) 449 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null)
797386 26-Aug-08 26-Aug-08 122 (null) (null) (null) 3980 3 (null) 14402 (null) 218925 (null) 734956 (null) (null) 476 (null) (null) (null) (null) 1 E Y (null) 100035417 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) 740071 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null)
916076 26-Aug-08 31-Dec-12 122 (null) (null) (null) 3980 1 4 14402 (null) 218925 (null) 734956 (null) (null) 476 (null) (null) (null) (null) 1 B Y (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null)
797386 25-Feb-08 25-Aug-08 122 (null) (null) (null) 3980 1 (null) 14402 (null) 218925 (null) 734956 (null) (null) 476 (null) (null) (null) (null) 1 E Y (null) 100035417 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) 740071 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) -
Query to find out the time used by an user for an application
Hello All,
I want to know the query to find out the whole time used by the user for an application. Please view the below data
Employee:
SNO EMP_ID EMP_NAME EMP_DATE LOGIN_TIME LOGOUT_TIME
1 10 Visu 21-Nov-2010 06:30:00 07:30:00
2 10 Visu 21-Nov-2010 06:40:00 07:20:00
3 10 Visu 21-Nov-2010 06:50:00 07:50:00
4 10 Visu 21-Nov-2010 07:30:00 08:30:00
5 10 Visu 21-Nov-2010 09:30:00 10:30:00
By checking the above data we can say that the total time Visu used the application is
8.30 - 6.30 (From 1,2,3,4 records) = 2hrs
10.30 - 9.30 (Based on 5th rec) = 1hr
So the total time Visu used the application would be 3 hrs = 180 mins.
Could you please help me in getting the result from that data using a query?odie_63 wrote:
I think it may be solved with analytics too.
with t1 as (
select 1 sno,10 emp_id,'Visu' emp_name,'21-Nov-2010' emp_date,'06:30:00' login_time,'07:30:00' logout_time from dual union all
select 2,10,'Visu','21-Nov-2010','06:40:00','07:20:00' from dual union all
select 3,10,'Visu','21-Nov-2010','06:50:00','07:50:00' from dual union all
select 4,10,'Visu','21-Nov-2010','07:30:00','08:30:00' from dual union all
select 5,10,'Visu','21-Nov-2010','09:30:00','10:30:00' from dual
t2 as (
select emp_id,
emp_name,
emp_date,
to_date(emp_date || login_time,'DD-MON-YYYYHH24:MI:SS') login_time,
to_date(emp_date || logout_time,'DD-MON-YYYYHH24:MI:SS') logout_time
from t1
t3 as (
select t2.*,
case
when login_time < max(logout_time) over(
partition by emp_id,emp_date
order by login_time
rows between unbounded preceding
and 1 preceding
then 0
else 1
end start_of_group
from t2
t4 as (
select t3.*,
sum(start_of_group) over(partition by emp_id,emp_date order by login_time) grp
from t3
t5 as (
select emp_id,
emp_date,
min(login_time) login_time,
max(logout_time) logout_time
from t4
group by emp_id,
emp_date,
grp
select emp_id,
numtodsinterval(sum(logout_time - login_time),'day') time_spent
from t5
group by emp_id
order by emp_id
EMP_ID TIME_SPENT
10 +000000000 03:00:00.000000000
SQL> SY. -
Query to find out controls displayed as in UI for an applet,along with view
Hi,
I am looking for a query to find out list of all the controls as displayed in UI applet along with applet's view.
Please note that in the query only mapped controls (those displayed in UI ) should come up.
Regards,
KunalHi,
If the EUL is an apps mode (EBS) EUL then the eu_username column is the apps user id or apps resp id. If you want to show only the responsibilities and convert those ids to names then you need to use the EUL5_GET_APPS_USERRESP function like this:
select ba_name, ba_developer_key, EUL5_GET_APPS_USERRESP(eu.eu_username, 'R') responsibility_name
from eul5_bas ba
, eul5_access_privs ap
, eul5_eul_users eu
where ba.ba_id = ap.gba_ba_id
and ap.ap_type = 'GBA'
and ap.ap_eu_id = eu.eu_id
and eu.eu_role_flag=1
order by 1,2,3Rod West -
Query to find out the Activities done against a table
Hi,
One table has been truncated and data reloaded into the table by the user. But at latter stage user deny that activity. I believe all these activities stored in any oracle 10g database table.
Need a query to find out the activities done on a specific date say 6th Sep.
This is too urgent. Thanks in advanceHi,
Welcome to the forum!
If you don't have enable table auditing maybe you can see last_ddl_time column of user_objects view:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> select * from test2;
COL1 COL2 COL3
1 1 3
1 2 3
1 3 3
SQL> select to_char(uo.created, 'DD/MM/YYYY HH24:MI:SS'), to_char(uo.last_ddl_time, 'DD/MM/YYYY HH24:MI:SS') from user_objects uo where uo.object_name = 'TEST2';
TO_CHAR(UO.CREATED,'DD/MM/YYYY TO_CHAR(UO.LAST_DDL_TIME,'DD/M
12/09/2009 12:20:26 12/09/2009 12:20:27
SQL> truncate table test2;
Table truncated
SQL> select to_char(uo.created, 'DD/MM/YYYY HH24:MI:SS'), to_char(uo.last_ddl_time, 'DD/MM/YYYY HH24:MI:SS') from user_objects uo where uo.object_name = 'TEST2';
TO_CHAR(UO.CREATED,'DD/MM/YYYY TO_CHAR(UO.LAST_DDL_TIME,'DD/M
12/09/2009 12:20:26 12/09/2009 14:01:21
SQL> Regards, -
SQL query to find out last login for each database
Hi everybody,
I have a view with following columns:
DatabaseSid, lastLogin, firstLogin.
I want to now the newest last_login date for every database.
SID First Login Last Login
e.g. Database1, 11.11.2011, 01.12.2011
Database1, 01.04.2012, 01.05.2012
Database3, 03.03.2004, 03.06.2005
Database 3 07.09.2012, 12.10.2012
How can I do a query to find out for eacht DB (DB1, DB2 and so on) the Last_Login Date?
Thank you in advance
SteveSteve wrote:
Hi everybody,
I have a view with following columns:
DatabaseSid, lastLogin, firstLogin.
I want to now the newest last_login date for every database.
SID First Login Last Login
e.g. Database1, 11.11.2011, 01.12.2011
Database1, 01.04.2012, 01.05.2012
Database3, 03.03.2004, 03.06.2005
Database 3 07.09.2012, 12.10.2012
How can I do a query to find out for eacht DB (DB1, DB2 and so on) the Last_Login Date?
Thank you in advance
SteveI'm curious as to how you collect this information from multiple databases into one database, and of what value the data is once you have it. -
SQL Query to Find out User has what all resources provisioned !
Hi Guys ,
Does any one have a SQL query to find out what resources are provisioned to a particular user ?
Thanks
SurenHi,
Hope this will help you.
SELECT distinct usr_login as "IdM User ID",
usr_employeeID as "Employee ID",
usr.USR_FIRST_NAME as "First Name",
usr.USR_LAST_NAME as "Last Name",
usr_status
as "User Status",
USR_EMP_TYPE as "Employee Type",
obj.obj_name as "Application Resource",
ost_status as "Application Resource Status",
FROM ost,oiu,obj,usr,obi
WHERE oiu.ost_key = ost.ost_key AND obj.obj_key = obi.obj_key AND oiu.usr_key = usr.usr_key
AND ost_status in ('Provisioned','Revoked','Disabled', 'Provisioning')
AND oiu.obi_key=obi.obi_key
AND usr_EmployeeID like '11111'
This query will provide all the resources to which the user is linked with and the resource status is in 'Provisioned','Revoked','Disabled', 'Provisioning' status for a particular employeed ID, I am not completely sure whether I have given the Employee ID column from USR table as correct or not. Verify once and query the DB -
How to use ONE query to find out tree structure?
ID------------upperID----------Name------------------------isFolder
1------------ 0---------- Folder
1------------------------------------1
2------------ 1------------ Folder 1- Sub
Folder--------------------1
3------------ 2------------
Folder1-Item1-A--------------------------0
4------------ 1------------ Folder 1- Sub
Item-----------------------0
Hi all, if I have a table like above to demonstrate the
folders and item relationship. This structure allows the user to
create unlimited folders and items.
Now I would like to use one query to find out the tree
structure of this table, how could I do the query.
Any help on this will be highly appreciated!
Thanks,
ezAlso, see this thread:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=7&threadid=12 55788&enterthread=y -
How to find out no. of records or repeating frame in a page
Hi All,
How do I find out how many records have been displayed on a particular page?
I'm having a repeating frame, and I want to know print another item, on a condition that if the records printed on the page are less than 5 then it should be printed otherwise not.
The item to be printed is not a part of the repeating frame whoz occurences have to be counted.
Regards
NaveenHi Naveen
You can create a Packaged varaible that acts as
global variable , and you can increment this
variable in the repeating frames Format Trigger .
Based on the value of the variable , you can
return true or false for the item that you want to
display . -
How to find out that a record is empty or null
hi
how can i find out that a record is empty or null.
in other languages when a object or record is not initialized it will be null.
after initialization how can i find out its values are null. so far i tried this
declare
v_r_emp emp%rowtype := null;
BEGIN
if (v_r_emp is null) then
dbms_output.put_line('record is not initialized');
end if;
END;
it seems in plsql we can assign null but cannot compare it with null clause why? if we are able of assign null we must should about to compare it with null too.
also how record can be made empty. how can we find out that a record variable is empty
please help me to understand the concept
thanksYou need to check every element in the record.
-
Query to find out the list of user who have delete access
Hi,
I need a query to find out the list of users who have delete access on perticular folder/universe/ reports in infoview.
Please advice.
Regards,
Neo.orton607 wrote:
thanks for replying guys. But the thing is i am using dynamic sql execute immediate in my package, so i want those tables also and the schema name.
thanks,
ortonThis is not possible. The best you could do is to have a good guess.
Or how would you parse some dynamic statement as this:
v_suffix := 'loyees';
v_sql := 'Select count(*) from (select ''nonsense'' col1 from emp'||v_suffix||') where col1 = ''Y'''';
execute_immediate(v_sql);
...What is the table name? How do you want to parse that?
Better rewrite all dynamic SQL statements into non dynamic ones. Or do the source control logic for those dynamic parts in an extra module. For example implement your own dependency table and force every developer to add there all dynamic parts. -
Is there any way I can find out the service record on this mac ?
I purchased a used QS from an authorized apple dealer at their after boxing day sales event. This QS is extremely quite compared to my polar express MDD.
Is there any way I can find out the service record on this mac ?
Somewhere away back when I heard that by knowing the serial number the details of the service record on the given mac could be found. However in those days I only bought new. These days with mac's inability to run applications that require the for real OS 9 ( not classic ) I have to scour the used market. I have some high end audio midi programmes ( for example emagic, cubase VST score ) that do the job and sometimes better then then the OS X versions.Hello,
You can use System.getProperty("SAPSYSTEMNAME"); in your UDF as specified in this thread.
Get name of XI System in mapping
Hope this helps,
Mark
Edited by: Mark Dihiansan on Apr 27, 2011 7:51 AM -
Query to find out which process consuming more cpu?
Hi All,
some one please tell me the query to find out which process is consuming more
cpu resources?
Thanks and Regards
SrikanthUse V$SESSTAT to determine which sessions are using most CPU, and investigate what SQL these users/sessions are executing:
SQL> select ss.sid, se.command, ss.value CPU, se.username, se.program
from v$sesstat ss, v$session se
where ss.statistic# in
(select statistic#
from v$statname
where name = 'CPU used by this session')
and se.sid=ss.sid
order by ss.value desc; -
Query to find out whether a table is sub-partitoned , composite type one
Could you please let me know the query to find out whether a paritioned table
is
1). composite paritioned one.
2). sub-paritioned one.
I find that there are 2 cols in all_tab_partitions view, which lets me know
1). COMPOSITE VARCHAR2(3)
To find composite paritioned one or not.
2). SUBPARTITION_COUNT NUMBER
To find whether a table is sub-paritioned one or not.
Any light on the above topic is highly appreciated.So it seems you've found the answer yourself?
with »user_tab_partitions« and »user_tab_subpartitons« you'll get all the neccessary information you are looking for. -
Query to find out license products installed
hai dba
tell me the query to find out what r hte products installed r licensed??
regards
dba1) From OAM: Oracle Applications Manager > Site Map > License Manager > Reports > License Products/Shared Products
2) Use $AD_TOP/sql/adutconf.sql
3) Use the following query:
SQL> select fa.APPLICATION_SHORT_NAME, fpi.PATCH_LEVEL, DECODE(fpi.STATUS, 'I','Installed',
'S','Shared', 'N', 'Inactive', fpi.STATUS) Status , fpi.DB_STATUS
from fnd_product_installations fpi,FND_APPLICATION fa
where fpi.APPLICATION_ID in (
select APPLICATION_ID from FND_APPLICATION)
and fa.APPLICATION_ID=fpi.APPLICATION_ID;
Maybe you are looking for
-
Can anyone help? Can I get my iTunes library from my Ipad touch into my new PC? From what I've read, it looks like I have to buy a special software to move it over. However, I thought when I bought the ipod that it said I could have the library on
-
I need MP4 export plugin for Premiere 6.5
Hi there, i have Premiere 6.5 DV500 Pinnacle, and Windows XP but when i import something, the quality is ... Damn it! Is very difficult upload a video in Youtube with good looking. I tried to export with indeo 4.4 ("best quality"), but i have to many
-
Why does a new desktop creation unexpectedly initiate with a background differing from the originating desktop? How can I control or eliminate this behavior?
-
I'm using InDesign CS3 and I encounter the following problem. As soon as I add effects to an object (especially transparency) the whole page where the effect is applied(no matter wether master or else) gets affected: tekst becomes 'thinner', colors t
-
Can I upgrade my Macromedia studio 8 Fireworks 8 to CS3? I have a license for CS3 design suite.