How to write the query to find the duplicate rows?
Hi,
How will I find the duplicate rows in the table?
I have a table called ITEM
Select item_no,mfg_id from item
Item Mfg_ID
178 06278
178 06589
238 5489
289 7895
289 7596
Now I want to find only the duplicate rows i.e.,178 & 289 is coming twice.
How will get the all duplicate rows in the table?
nihar2 wrote:
Convert to
SELECT it.item,
im.mfg_item,
im.manufacturer,
im.description
FROM (SELECT it.item,
im.mfg_item,
im.manufacturer,
im.description,
count(it.item) over(partition by it.item order by it.item) cnt
FROM item it,item_mfg im
WHERE it.u##item=im.u##item)
WHERE cnt > 1
But I tried It show not valid identifier.You can't use the table aliases from the sub-query...
SELECT item,
mfg_item,
manufacturer,
description
FROM (SELECT it.item,
im.mfg_item,
im.manufacturer,
im.description,
count(it.item) over(partition by it.item order by it.item) cnt
FROM item it,item_mfg im
WHERE it.u##item=im.u##item)
WHERE cnt > 1
Similar Messages
-
How to write select query for all the user tables in database
Can any one tell me how to select the columns from all the user tables in a database
Here I had 3columns as input...
1.phone no
2.memberid
3.sub no.
I have to select call time,record,agn from all the tables in a database...all database tables have the same column names but some may have additional columns..
Eg: select call time, record,agn from ah_t_table where phone no= 6186759765,memberid=j34563298
Query has to execute not only for this table but for all user tables in the database..all tables will start with ah_t
I am trying for this query since 30days...
Help me please....any kind of help is appreciated.....Hi,
user13113704 wrote:
... i need to include the symbol (') for the numbers(values) to get selected..
eg: phone no= '6284056879'To include a single-quote in a string literal, use 2 or them in a row, as shown below.
Starting in Oracle 10, you can also use Q-notation:
http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements003.htm#i42617
...and also can you tell me how to execute the output of this script. What front end are you using? If it's SQL*Plus, then you can SPOOL the query to a file, and then execute that file, like this:
-- Suppress SQL*Plus features that interfere with raw output
SET FEEDBACK OFF
SET PAGESIZE 0
-- Run preliminary query to generate main query
SPOOL c:\my_sql_dir\all_ah_t.sql
SELECT 'select call time, record, agn from '
|| owner
|| '.'
|| table_name
|| ' where phone_no = ''6186759765'' and memberid = j34563298'
|| CASE
WHEN ROW_NUMBER () OVER ( ORDER BY owner DESC
, table_name DESC
) = 1
THEN ';'
ELSE ' UNION ALL'
END AS txt
FROM all_tables
WHERE SUBSTR (table_name, 1, 4) = 'AH_T'
ORDER BY owner
, table_name
SPOOL OFF
-- Restore SQL*Plus features that interfere with raw output (if desired)
SET FEEDBACK ON
SET PAGESIZE 50
-- Run main query:
@c:\my_sql_dir\all_ah_t.sql
so that i form a temporary view for this script as a table(or store the result in a temp table) and my problem will be solved..Sorry, I don't understand. What is a "temporary view"? -
How to write a query to get the time difference of two varchar type time columns
Hi,
I want to get the time difference between the two varchar type columns.please see the attached image for more details:
My requirement is like:
timestarted
timeended
timediff
9:00:00
10:00:00
1:00
9:15
9:30:00
0:15Storing time alone as VARCHAR2 value is a incorrect design. Always store it as DATE or TIMESTAMP.
If you already have a messed up design and cant change it, then you need to convert your VARCHAR2 time into a DATE or TIMESTAMP and find the difference. I have converted it to TIMESTAMP and obtained the difference as INTERVAL.
SQL> with t
2 as
3 (
4 select '09:00:00' timestarted, '10:00:00' timeended from dual
5 union all
6 select '09:15:00' timestarted, '09:30:00' timeended from dual
7 )
8 select timestarted
9 , timeended
10 , (timeended - timestarted) day to second diff
11 from (
12 select to_timestamp('01011900' || timeended, 'ddmmyyyyhh24:mi:ss') timeended
13 , to_timestamp('01011900' || timestarted, 'ddmmyyyyhh24:mi:ss') timestarted
14 from t
15 );
TIMESTARTED TIMEENDED DIFF
01-JAN-00 09.00.00.000000000 AM 01-JAN-00 10.00.00.000000000 AM +00 01:00:00.000000
01-JAN-00 09.15.00.000000000 AM 01-JAN-00 09.30.00.000000000 AM +00 00:15:00.000000
SQL> -
How to write SQL query to flatten the hierarchy
Hi,
I have person table which has recursive hierarchy and I wish to flatten it upto 5 levels.
I am using Oracle10g and I have written following query to flatten the hierarchy
SELECT
ID,
level lvl,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 1) AS level_1,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 2) AS level_2,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 3) AS level_3,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 4) AS level_4,
REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 5) AS level_5
FROM cmt_person
CONNECT BY manager_id = PRIOR id
and level<=5
The person table have more than a million records.
Here I am getting the correct output but this query is taking a lot of time to run.
I am looking at a SQL query without use of connect by to get the required output.
To recreate the issue, you can use this query in HR schema of Oracle and use Employees table.
Any help would be greatly appreciated.
Thanks,
RaghvendraI tried to rewrite the query without using regular expression and connect by. Here is the code:
SELECT
cmt_person.id ,
cmt_person.fname as mgr1,
case when cmt_person2.manager_id=cmt_person.id then (cmt_person2.fname ) end as mgr2,
case when cmt_person3.manager_id=cmt_person2.id then (cmt_person3.fname ) end as mgr3,
case when cmt_person4.manager_id=cmt_person3.id then cmt_person4.fname end as mgr4,
case when cmt_person5.manager_id=cmt_person4.id then cmt_person5.fname end as mgr5
FROM
cmt_person,
cmt_person cmt_person2,
cmt_person cmt_person3,
cmt_person cmt_person4,
cmt_person cmt_person5
WHERE
cmt_person2.manager_id(+)=cmt_person.id and
cmt_person3.manager_id(+)=cmt_person2.id and
cmt_person4.manager_id(+)=cmt_person3.id and
cmt_person5.manager_id(+)=cmt_person4.id
order by 2,3,4
I got following output:
emplo000000000200100 Bobby Khasha Rahul Rajesh
emplo000000000200099 Bobby Khasha Rahul Ajay
emplo000000000200101 Bobby Khasha Rahul Swati
emplo000000000200320 Bobby Khasha Rahul Jinesh
emplo000000000201231 Bobby Khasha Test123
emplo000000000201230 Bobby Khasha User1_Domain
emplo000000000201227 Bobby Khasha User1_World
emplo000000000200104 Bobby Khasha Yitzik Natalia
emplo000000000200103 Bobby Khasha Yitzik Andrew
total 9 rows
But this is partially correct output. I want output like this:
emplo000000000200097 Bobby
emplo000000000200087 Bobby Khasha
emplo000000000200102 Bobby Khasha Yitzik
emplo000000000200103 Bobby Khasha Yitzik Andrew
emplo000000000200104 Bobby Khasha Yitzik Natalia
emplo000000000201227 Bobby Khasha User1_World
emplo000000000201231 Bobby Khasha Test123
emplo000000000201230 Bobby Khasha User1_Domain
emplo000000000200098 Bobby Khasha Rahul
emplo000000000200099 Bobby Khasha Rahul Ajay
emplo000000000200100 Bobby Khasha Rahul Rajesh
emplo000000000200320 Bobby Khasha Rahul Jinesh
emplo000000000200101 Bobby Khasha Rahul Swati
total 13 rows
Do you know what I should do to get this output.
Thanks,
Raghvendra -
How to write a query to get the total as a last row
Hi,
I need to get something like this ....
|TEAM LEADER| TEAM | OCT TRN | EMPS| YTD% |
|_____________|__________|__________|______|_______|
| JOHN | JD Team | 12 | 12 | 100 |
|_____________|__________|__________|______|_______|
| Total | | 12 | 12 | 100 |
|_____________|__________|__________|______|_______|
I have to get the last row as total adding the number columns ...
Thanks in advance ...Take a look at the GROUP BY ROLLUP feature:
create table t1
(team_name varchar2(30)
,wins number
,losses number
insert into t1 values ('Hornets',3,1);
insert into t1 values ('Panthers',4,0);
insert into t1 values ('Wolves',2,2);
insert into t1 values ('Badgers',0,4);
insert into t1 values ('Hornets',1,3);
commit;
select decode(team_name,
NULL,'TOTAL',
team_name) team_name, sum(wins), sum(losses)
from t1
group by rollup(team_name);
TEAM_NAME SUM(WINS) SUM(LOSSES)
Badgers 0 4
Hornets 4 4
Panthers 4 0
Wolves 2 2
TOTAL 10 10 -
Query to find the list of users having access to a particular scenario
Hi,
I am learning Hyperion Planning 9.2 x version. I wanted to know the query to find the list of users having access to Plan Iteration - 1 scenarion.
As I am new to Hyperion Essbase and Hyperion Planning, I am assuming these ideas work out to get the desired result.
1) As Hyperion Planning uses Relational DB to store the User Security information, we can query the list of users who is having access to Plan Iteration - 1 Scenario.
I am not sure if this solution works. Please correct me If I am wrong.
2) We can also query from the essbase editor to find out who all having access to this scenario.
If the above is correct, can you please provide me the query.
I am really need of this and I will be happy if any one provide the solution.
Thanks & Regards,
Upendra. BesthaHi,
If you are looking for some SQL to retrieve the access rights by member then you can use something like (SQL Server code though can easily be modified for Oracle)
SELECT usr.object_name as Username,mem.object_name as Member,
'Access Rights' = CASE acc.access_mode
WHEN -1 THEN 'None'
WHEN 1 THEN 'Read'
WHEN 2 THEN 'Write'
WHEN 3 THEN 'Write'
ELSE 'Unknown' END,
'Relation' = CASE acc.flags
WHEN 0 THEN 'Member'
WHEN 5 THEN 'Children'
WHEN 6 THEN 'Children (inclusive)'
WHEN 8 THEN 'Descendants'
WHEN 9 THEN 'Descendants (inclusive)'
ELSE 'Unknown' END
FROM
hsp_access_control acc, hsp_object mem, hsp_object usr
WHERE acc.object_id = mem.object_id
AND acc.user_id = usr.object_id
AND mem.object_name = 'Plan Iteration - 1'
Cheers
John
http://john-goodwin.blogspot.com/ -
Query to find the memory of database in oracle,sql
Hi All,
Please let me know the query to find the memory of database in oracle,sql.
Thanks,
sajithHow do I find the overall database size?
The biggest portion of a database's size comes from the datafiles. To find out how many megabytes are allocated to ALL datafiles:
select sum(bytes)/1024/1024 "Meg" from dba_data_files;
To get the size of all TEMP files:
select nvl(sum(bytes),0)/1024/1024 "Meg" from dba_temp_files;
To get the size of the on-line redo-logs:
select sum(bytes)/1024/1024 "Meg" from sys.v_$log;
Putting it all together into a single query:
select a.data_size+b.temp_size+c.redo_size "total_size"
from ( select sum(bytes) data_size
from dba_data_files ) a,
( select nvl(sum(bytes),0) temp_size
from dba_temp_files ) b,
( select sum(bytes) redo_size
from sys.v_$log ) c;
Another query ("Free space" reports data files free space):
col "Database Size" format a20
col "Free space" format a20
select round(sum(used.bytes) / 1024 / 1024 ) || ' MB' "Database Size"
, round(free.p / 1024 / 1024) || ' MB' "Free space"
from (select bytes from v$datafile
union all
select bytes from v$tempfile
union all
select bytes from v$log) used
, (select sum(bytes) as p from dba_free_space) free
group by free.p
This is what I use :P From http://www.orafaq.com/wiki/Oracle_database_FAQ#How_do_I_find_the_overall_database_size.3F -
Query to find the list of BP without having Particular GL transactions.
Hi Experts,
I want the query to find the List of Business partner who is not having Journal entry for Certain General ledger.
Scenario: we are creating JE for TDS posting.
so, i want to know the list of BP , who and all not having particular TDS GL for the particular period.
Thanks in advance,
DwarakHi Dwarak,
Sure, no problem
DECLARE @AcctCode AS NVARCHAR(100)
SELECT @AcctCode=T0.AcctCode FROM OACT T0 WHERE T0.AcctCode='[%0]'
DECLARE @DateFrom AS DATETIME
SELECT @DateFrom=T1.RefDate FROM JDT1 T1 WHERE T1.RefDate=[%1]
DECLARE @DateTo AS DATETIME
SELECT @DateTo=T2.RefDate FROM JDT1 T2 WHERE T2.RefDate=[%2]
SELECT CardCode FROM OCRD WHERE CardType='S'
AND CardCode NOT IN(
SELECT DISTINCT ContraAct FROM JDT1
WHERE Account=@AcctCode AND RefDate BETWEEN @DateFrom AND @DateTo)
Ok, now, here's the problem that I just encountered. This query will work, but, no matter how we fill the parameter, it will show you the very same result. To be honest, I don't know what's wrong with this query.
If you change all the variables ( @AcctCode and @DateFrom and @DateTo ) directly, it will give you the accurate result. Take this as an example:
SELECT CardCode FROM OCRD WHERE CardType='S'
AND CardCode NOT IN(
SELECT DISTINCT ContraAct FROM JDT1
WHERE Account='10030201' AND RefDate BETWEEN '2011-09-01' AND '2011-09-20')
I hard-code the account code, date from and date to for selection. System will show you the accurate result, but using parameter as in first query, system show same result no matter how we fill the parameter.
Sorry, it seems that I could only partially solved your problem here. I already tried to create a stored procedure and executing the stored procedure with parameter, but still, somehow SBO show very same result no matter if we change the parameter.
So, my solution need user to manually change the parameter in query. I know, this is a stupid solution, I'm afraid I can't help you to achieve perfect solution here. Maybe anyone here in the forum could guide me to fix my mistake in first query and how to rectify it?
Best Regards,
Hendry Wijaya -
Query to find the the free space in raw disks
I am new to ASM.
What is the query to find the free space in the raw disks in ASM diskgroup.? Can i get space info about individual raw disks in the disk group?
Is there an ip address for the ASM disk group? If so how can i find it?below query will give you total and free space for each raw disk from a disk group.
select dg.name, d.name, d.total_mb, d.free_mb from v$asm_disk d, v$asm_diskgroup dg where dg.group_number=d.group_number order by 1;
There no IP address attached to ASM disk group. Why do you want associate IP address with a Disk group? -
Query to find the long running concurrent requests morethan 2 hours
Can any one please provide the " Query to find the long running concurrent requests which are running more than 2 hours"
You need to find the different between the current time/date and FND_CONCURRENT_REQUESTS.ACTUAL_START_DATE for the running requests.
More details can be found in the following notes:
Note: 187504.1 - bde_request.sql - Process and Session info for one Concurrent Request (11.5)
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=187504.1
Note: 134035.1 - ANALYZEREQ.SQL - Detailed Analysis of One Concurrent Request (Release 11 and up)
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=134035.1
Note: 751438.1 - How To Check List , Start And End Dates Of A Parent Concurrent Request And All Childs
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=751438.1 -
Query to find the second maximum date in a table
please give me the query to find the second maximum date in a table
You can try with this
SELECT empno
,hiredate
FROM emp a
WHERE 2 = (SELECT COUNT(DISTINCT hiredate)
FROM emp b
WHERE b.hiredate >= a.hiredate
OR
SELECT empno
,hiredate
FROM (SELECT ROWNUM row_num
,empno
,hiredate
FROM emp a
ORDER BY hiredate ASC
WHERE row_num = 2;Regards
Arun -
Sql query to find the space in between the sentense
hi,
can anybody tell me the query to find the space in between the data
chandanNot sure what you mean, but you might want to take a look at INSTR, like in
instr (txt, ' ') -
Query to find the Base tables of views
Hi,
Can you pl let me know the query to find the base tables on which the view is based.I looked into views like ci_view_definitions but i could not find them.
Thanks for your help
thanx,
Suji.select vw.name viewname, nvl( tabdef.name, vwdef.name) "based on"
from ci_view_definitions vw
, i$sdd_vwtab
, ci_view_definitions vwdef
, ci_table_definitions tabdef
where view_ref = vw.id
and table_ref = tabdef.id (+)
and table_ref = vwdef.id (+) -
Query to find the application user
Hi,
what is the query to find the application user in sql command?
I tried the below query
select app_user from dual;
app_user invalid identifierthanks.Use bind variable notation:
select :app_user from dualThis is a reduced example, right? Can't see any reason to run such a query instead of using one of the documented methods of referencing built-in substitution values.
Please try to use the documentation to answer such basic questions. -
Query to find the class name that has the maximum number of students ?
I need the query to find the [class Name] which has the most number of students. please look below at the tables
Students Table
StudentId StudentName ClassID
1 xxx 1
2 yyy 1
3 zzz 1
4 fff 2
5 ttt 2
Classes Table
ClassID ClassNane
1 CSHARP
2 JSHARP
The result should be : CSHARP
since there are 3 students in CSHARP and 2 students in JSHARP class
Appreciate your help
ThanksTry:
DECLARE @Classes TABLE (
ClassID INT identity(1, 1) PRIMARY KEY
,ClassName VARCHAR(50)
INSERT INTO @Classes (ClassName)
VALUES ('CSharp')
,('JSharp')
DECLARE @Students TABLE (
StudentID INT identity(1, 1) PRIMARY KEY
,StudentName VARCHAR(10)
,ClassID INT
INSERT INTO @Students (
StudentName
,ClassID
VALUES (
'xxx'
,1
'yyy'
,1
'zzz'
,1
'fff'
,2
'ttt'
,2
SELECT TOP (1)
WITH TIES C.ClassName
FROM @Classes C
INNER JOIN @Students S ON C.ClassID = S.ClassID
GROUP BY C.ClassID
,C.ClassName
ORDER BY COUNT(S.StudentID) DESC
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Maybe you are looking for
-
How can I fill a table of objects from cursor with select * bulk collect???
Hi All, I have a TYPE as OBJECT create or replace type dept2_o as object ( deptno NUMBER(2), dname VARCHAR2(14), loc VARCHAR2(13)); I can fill a table of objects from cursor with out select * bulk collect...., row by row declare TYPE dept2_t IS TABLE
-
Import from camcorder stops after few seconds. Never used to! Ideas?
Hi you wonderful experts and enthusiast out there. Been using iMovie HD 5 successfully for a couple of years, but all of a sudden I can't import from my camcorder. I have a long, unbroken, recorded sequence on the camcorder, but when I go to import i
-
Hey Guys, I am having a problem with cfloop. What I am trying to do is calculate points on an Oline March Madness Pool. I need to evaluate if the user picks are equal to the game winners. I can do it if I manually type each pick # and each game # but
-
How to conncect dvi to vga connector mac
I have a MBP, late 2008. What cables (manufactures) will I need to connect my MBP to HDTV?
-
Learn to Play - Resetting Display Preferences.
While I was exploring guitar 'Learn to Play', my little boy mashed the keyboard resulting in the lesson display preferences changing and now I can't figure out how to change them back. Specifically, the guitar neck at the bottom of the display has di