Returns all duplicate rows, where the columns correspond
Dear members,I have a table that contains duplicates, and the query should return only the rows where the columns correspond...
create master table (varchar2 (10) firstname, lastname varchar2 (10), code VARCHAR2 (3), place varchar2 (10));
insert into Master values ('bob', 'John', '1', 'atlanta');
insert into Master values ('bob', 'John', '1', 'atlanta');
insert into Master values ('bob', 'John', '1', 'atlanta');
insert into Master values ('test', 'John', '1', 'atlanta');
Insert into master values('bob','john','1','bank');
The application should we 3 rows.
Bob-john-1-atlanta
Bob-john-1-atlanta
Bob-john-1-atlanta
I tried a few changes to query such as select * from master M, mater n where m.firstname = n.firstname and...
Is there another way to do this...
Thanks in advance...
select firstname,
lastname,
code,
place
from (
select m.*,
count(*) over(partition by firstname,lastname,code,place) cnt
from master m
)
where cnt > 1
order by firstname,
lastname,
code,
place
/
FIRSTNAME LASTNAME COD PLACE
---------- ---------- --- ----------
bob john 1 atlanta
bob john 1 atlanta
bob john 1 atlanta
SQL>
SY.
Tags: Database
Similar Questions
-
Request to remove row where the value of column contains alphabets
Hello
Could someone please help me to get this application working.
Request to remove row where the value of column contains alphabets.
DELETE FROM BIN_ITEM WHERE order_nmb LIKE '% [A - Z] % ' | LIKE '% [a - z] %'
Thank you and best regards,
Madam.
SELECT order_nmb FROM BIN_ITEM WHERE regexp_count(order_nmb,'[0-9]') = 0
----
Ramin Hashimzade
-
Select only records where the column values are not all equal to zero
Hi everyone, it seems so easy, but it has left me speechless on the research in a way that is clean, easy to achieve. I know when someone replies, I'm going to kick me. So, let's assume this is what I have:
I need an external application around it or something which will select only 'Type 1'... that is, if all months are each equal to zero, do not include the record in the result set.with mytable as ( select 'Type 1' as itemtype, 'JAN' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'FEB' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'MAR' as monthname, 5 as theval from dual union all select 'Type 1' as itemtype, 'APR' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'MAY' as monthname, 4 as theval from dual union all select 'Type 1' as itemtype, 'JUL' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'AUG' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'SEP' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'OCT' as monthname, 7 as theval from dual union all select 'Type 1' as itemtype, 'NOV' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'DEC' as monthname, 2 as theval from dual union all select 'Type 2' as itemtype, 'JAN' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'FEB' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'MAR' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'APR' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'MAY' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'OCT' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'NOV' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'DEC' as monthname, 0 as theval from dual ) select itemtype, sum (case monthname when 'JAN' then theval else 0 end) as JAN, sum (case monthname when 'FEB' then theval else 0 end) as FEB, sum (case monthname when 'MAR' then theval else 0 end) as MAR, sum (case monthname when 'APR' then theval else 0 end) as APR, sum (case monthname when 'MAY' then theval else 0 end) as MAY, sum (case monthname when 'JUN' then theval else 0 end) as JUN, sum (case monthname when 'JUL' then theval else 0 end) as JUL, sum (case monthname when 'AUG' then theval else 0 end) as AUG, sum (case monthname when 'SEP' then theval else 0 end) as SEP, sum (case monthname when 'OCT' then theval else 0 end) as OCT, sum (case monthname when 'NOV' then theval else 0 end) as NOV, sum (case monthname when 'DEC' then theval else 0 end) as DEC from mytable group by itemtype order by itemtype
In summary to get a total of zero is not an option, because I could have-15 and + 15 in different columns, in which case, the recording should be displayed.
Something as simple as... 'not the case (oct = 0 and 0 nov and dec = 0...) at the end is all it seems to me necessary. I thought to add a case for each column clause, but that seems not very effective. Ideas?
Thanks in advance!
Mark
Edit... I know not what follows will work using the MINUS operator, but my actual query is really huge, and I don't want to have to write it twice...
{code}
Select
ItemType,
sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
sum (case monthname when "APR" then Val else 0 end) as APR.
sum (case when monthname 'MAY', then Val else 0 end) either.
sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
sum (case monthname when "JUL" then Val else 0 end) as JUL,.
sum (case monthname when "AUG" then Val else 0 end) as AUG.
sum (case monthname when "MS" then Val else 0 end) as MS.
sum (case monthname when "OCTS" then Val else 0 end) OCT.
sum (case monthname when "NOV" then Val else 0 end) as NOV.
sum (case monthname when 'DEC' then Val else 0 end) as DEC
FROM MyTable
Group of itemtype
less
Select
ItemType,
Jan, Feb, mar, Apr, may, June, July, August, Sept, oct, nov, dec
de)
Select
ItemType,
sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
sum (case monthname when "APR" then Val else 0 end) as APR.
sum (case when monthname 'MAY', then Val else 0 end) either.
sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
sum (case monthname when "JUL" then Val else 0 end) as JUL,.
sum (case monthname when "AUG" then Val else 0 end) as AUG.
sum (case monthname when "MS" then Val else 0 end) as MS.
sum (case monthname when "OCTS" then Val else 0 end) OCT.
sum (case monthname when "NOV" then Val else 0 end) as NOV.
sum (case monthname when 'DEC' then Val else 0 end) as DEC
FROM MyTable
Group of itemtype
)
where (oct = 0 & nov = 0 and dec = 0 and jan = 0 and 0 = Feb and mar = 0
apr = 0 and may = 0 and = 0 jun and Jul = 0 and aug = 0 and Ms = 0
)
order of itemtype
{code}
Change again... OK, I guess that I am answering my own question here, but I think that by using a WITH to write the main request once clause and then selecting * twice using the MINUS operator between where the second query is where (oct = 0, etc.) is what I need. If anyone has better suggestions, please let me know! Here's the logic of nickname for what I come up with to date...
{code}
WITH mainquery as (select all)
Select * from mainquery
less
Select * from mainquery where (oct = 0, nov = 0, etc...)
{code}
Thanks again!
Mark
Published by: user455268 on March 1, 2012 19:13
Published by: user455268 on March 1, 2012 19:16Hello
You can do it with a HAVING clause:
select itemtype, sum (case monthname when 'JAN' then theval else 0 end) as JAN, sum (case monthname when 'FEB' then theval else 0 end) as FEB, sum (case monthname when 'MAR' then theval else 0 end) as MAR, sum (case monthname when 'APR' then theval else 0 end) as APR, sum (case monthname when 'MAY' then theval else 0 end) as MAY, sum (case monthname when 'JUN' then theval else 0 end) as JUN, sum (case monthname when 'JUL' then theval else 0 end) as JUL, sum (case monthname when 'AUG' then theval else 0 end) as AUG, sum (case monthname when 'SEP' then theval else 0 end) as SEP, sum (case monthname when 'OCT' then theval else 0 end) as OCT, sum (case monthname when 'NOV' then theval else 0 end) as NOV, sum (case monthname when 'DEC' then theval else 0 end) as DEC from mytable group by itemtype HAVING MIN (theval) != 0 OR MAX (theval) != 0 order by itemtype ;
If the values are all 0, then the MIN and MAX will be 0.
If the MIN or MAX is not 0, the values are all 0.This assumes that the combination (itemtype, monthname) is unique, because it is in your sample data.
If this is not the case, start with a subquery that GROUPs BY itemtype, monthname, so that when you get to the main request, this combination will be unique. -
Mark from a table where the column value is a colon-delimited list
Version: Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
Hello
This is a new query of a query Frank helped me with:
Demand is all users to restrict the report based on a multiple selection on the front-end server (application APEX) filter.
The filter returns that a colon-delimited list and the data in the table can be saved in a delimited by a colon list too. There may be 1 to n values (up to 4000 characters).
I need a WHERE clause that will allow a match, if it exists, between the data in the column of the Table and the Mult-selection list filter.
The abbreviated for this post query would be something like:
SELECT slt_id, slt_item, slt_owner
OF slt_dashboard
WHERE slt_owner IN (colon delimited page list);
The Create Table and Insert statements:
CREATE TABLE slt_dashboard ( dashboard_id NUMBER, slt_id VARCHAR2(10), slt_item VARCHAR2(2500), slt_owner VARCHAR2(4000), slt_type VARCHAR2(25), slt_year NUMBER, parent_id NUMBER ); --Insert slt_dashboard INSERT INTO slt_dashboard(dashboard_id,slt_id,slt_item,slt_owner,slt_type,slt_year,parent_id) VALUES (12,'1.1','Implement revenue enhancement initiatives','E15889:JPARISI:BDUR63','Business Commitment',2014,6); INSERT INTO slt_dashboard(dashboard_id,slt_id,slt_item,slt_owner,slt_type,slt_year,parent_id) VALUES (13,'1.2','Strengthen our Energy position','KVROMAN','Business Commitment',2014,6);
I have a function to separate the list delimited by two points in a table for the IN clause, but because these values can be saved in a delimited list of Colon in the column of the Table, I have a problem, being able to analyze the data in the column, AND the filter data.
The function is:
CREATE OR REPLACE FUNCTION get_list( p_string IN VARCHAR2 ,p_delimiter IN VARCHAR2 DEFAULT ':' ) RETURN vc_array_1 PIPELINED IS l_string VARCHAR2( 32000 ); l_array wwv_flow_global.vc_arr2; BEGIN l_array := APEX_UTIL.string_to_table( p_string ,p_delimiter ); FOR i IN l_array.FIRST .. l_array.LAST LOOP PIPE ROW ( TRIM( l_array( i ) ) ); END LOOP; RETURN; END;
The function called in the query in the form (it's just for reference in case someone wanted to know):
SELECT ... FROM ... WHERE slt_owner IN (SELECT * FROM TABLE( get_list( :P115_SLT_OWNER ) ));
But I can't use this approach because the data in the Table can be saved in a delimited list of Colon too.
Desired output:
If the Mult-Select list filter contains: E15889:JPARISI then
1.1 implementation of the E15889 revenue improvement initiatives; JPARISI (it's a semicolon between the names)
If the multiple-selection list filter contains: KVROMAN then
1.2 strengthen our position of energy KVROMAN
If the multiple-selection list filter contains: BDUR63:KVROMAN then
1.1 implementation of the BDUR63 revenue improvement initiatives
1.2 strengthen our position of energy KVROMAN
Please let me know if something is not clear.
Thank you
Joe
I went to approach the Table and the Page works perfectly.
Thank you to everyone!
Thank you
Joe
-
SQL join on the two tables where the column as another column
Hi all
tried to get the results of a join between two tables where only one column is like another.
Table1 (nameA) examples: black2, green1
Table2 (Name) example: black2.location.uk.com, green1.location.uk.com
so, for example, I want to match all those in table1 with black2 column in table2 that begins with black2 and so of suite, if you see what im trying to get to!
My sql up to now:
but it errors:select * from schema.table1 a join schema.table2 b on a.nameA like concat('%', b.nameB, '%');
ORA-00909: invalid number of arguments
00909 00000 - "invalid number of arguments.
Any help or advice would be greatly appreciated, thank you!Or any of them should do...
select * from schema.table1 a join schema.table2 b on a.nameA like '%'||b.nameB||'%';
or
select * from schema.table1 a join schema.table2 b on instr(b.nameB,a.nameA) > 0
-
Where the column to enable or disable tracks (12.3.2.35)?
After the update of 12.3.2.35 I miss the column where I can click in order to activate or disable the track in the Playlist Layout "Title".
In previous versions, I used an AppleScript for marking and copying selected titles and now?
Thanks for help
JG
Boxes not appearing is not in iTunes 11 - https://discussions.apple.com/message/21933606#21933606 - to ensure that the preferences are set to display check boxes.
-
Check all the duplicate values in the column COUNT()
Hello
I'll do some tests, and for this I need to retrieve data based on a single column for example test_data_col, which-
1 to 3 or more count (test_data_col) for a given set of columns for example grp_col1, grp_col2, grp_col3 group
2. overall recovered lines, this particular column has some duplicate values. I don't need displayed duplicates, just whether or not duplicates exist.
Which could explain what I'm trying to do -
grp_col1, grp_col2, grp_col3, test_data_col
1, A, xyz, HELLO
1, A, xyz, HELLO
1, a, xyz, BYE
1, A, xyz, goodbye
2, C, pqr, WELCOME
2, C, pqr, GOOD MORNING
2, C, pqr, BAD MORNING
So for condition 1, I do something like that.
In this request, I want to do something that will tell me if the aggregate COUNT (test_data_col) has all the duplicate values it contains. Yet once, display the duplicates is not important here.SELECT COUNT(test_data_col) cnt, grp_col_1, grp_col2, grp_col3 FROM test_tab GROUP BY grp_col_1, grp_col2, grp_col3 HAVING COUNT(test_data_col) >= 3;
With the correct to replace coding / * some * logic /, I have following values.SELECT COUNT(test_data_col) cnt, grp_col_1, grp_col2, grp_col3, /*some logic*/ dup_val FROM test_tab GROUP BY grp_col_1, grp_col2, grp_col3 HAVING COUNT(test_data_col) >= 3;
CNT, grp_col_1, grp_col2, grp_col3, dup_val
4, 1, a, xyz, Y
3, 2, C, pqr, N
I have dup_val column to explain what I'm trying to achieve... Another way to know the existence of duplicates in the aggregate count will be fine.
My version of Oracle's Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0
Do you like the answer!Your somewhere logical can be like that
case when COUNT(test_data_col) != COUNT(distinct test_data_col) the 'Y' else 'N' end dup_val
-
2540 DeskJet not print all rows in the column
I am satisfied with my new 2540 Deskjet, except on the simple Excel documents it prints only a portion of the lines even if the grid is checked. This never happened with my old dell printer.
Hi CathB123,
Welcome to the HP Forums!
If printing works well in other programs, I recommend this site, print gridlines in a worksheet. I would also try using the HP print and Scan Doctor, in which case there may be a driver conflict.
Otherwise, if it does not help, please contact Microsoft Office technical support. The Agency supports, as I am not familiar with Excel.
Good luck!
-
SELECT where the column is NULL or a number
Hello
I am trying to use a query that the WHERE clause contains a column that can be NULL or a number. If it contains a number, I want to select the rows that contain the numerical value for this column; Otherwise, the rows that contain NULL for this column, as shown here:
SELECT col_1,
col_2,
etc...
OF CN_BGT_ENTRIES
WHERE grnt_id = p_grnt_id
AND subbgt_nbr = (SELECT MAX (subbgt_nbr) FROM CN_BGT_ENTRIES WHERE grnt_id = p_grnt_id);
in the opposite case
AND subbgt_nbr is null;
My strategy has been to create a cursor, EXTRACT the max value in l_subbgt_max and then use a BOX of the form:
SELECT col_1,
col_2,
etc...
OF CN_BGT_ENTRIES
WHERE grnt_id = p_grnt_id
AND (CASE
WHEN l_subbgt_max IS NULL THEN ' subbgt_nbr IS NULL; "
ELSE ' subbgt_nbr = l_subbgt_max; »
(END);
I tried every syntax since I can think of (for example, CASE NVL(l_subbgt_max,0) = 0) but continues to receive:
PL/SQL: ORA-00920: invalid relational operator
ORA-06550: line 13, column 3:
PL/SQL: SQL statement ignored
I know that I can DECLARE 2 sliders and then use a conditional to run one or the other, but in the interest of the growth and written some thing a little more sophisticated, I was hoping that someone with more experience SQL could tell me how [s] he would do this.
Thanks in advance for your time.I guess that l_subbgt_nbr is a variable?
In any case, something like this:
SELECT col_1, col_2, etc ... FROM CN_BGT_ENTRIES WHERE grnt_id = p_grnt_id AND ( ( l_subbgt_nbr is null and subbgt_nbr is null ) OR ( l_subbgt_nbr is not null and subbgt_nbr = (SELECT MAX(subbgt_nbr) FROM CN_BGT_ENTRIES WHERE grnt_id = p_grnt_id) ) );
Cheers, APC
Published by: APC on July 23, 2012 15:46
-
need of a query to row to the column transformation
Data in the table:SELECT friday_date FROM t2;
02/01/2009
09/01/2009
16/01/2009...
I need a query to get the result below fashion
Column
----------
1/2/20091/9/20091/16/2009
I tried to PIVOT and TRANSPOSES, this is impossible. I think because it's a date, maybe.
I tried code below also, but CONNECT_BY_ISLEAF will not work on "ORA-00904:"CONNECT_BY_ISLEAF": invalid identifier.
Thank youSELECT ltrim(sys_connect_by_path(FRIDAY_DATE,','),',') FRIDAY_DATE FROM ( SELECT row_number() OVER(ORDER BY FRIDAY_DATE) rno, FRIDAY_DATE FROM t2 ) WHERE CONNECT_BY_ISLEAF = '1' start WITH rno = '1' connect BY rno = PRIOR rno+1;
SQL> WITH t2 AS ( SELECT TO_CHAR ( NEXT_DAY ( DATE '2009-01-01' + (LEVEL - 1) * 7, 'friday' ), 'mm/dd/yyyy' ) friday_date FROM DUAL CONNECT BY LEVEL <= (DATE '2009-12-31' - DATE '2009-01-01') / 7) --- --- SELECT RTRIM ( XMLAGG (XMLELEMENT ( e, friday_date || ',' )).EXTRACT ('//text()'), ',' ) COLUMN_VALUE FROM t2 COLUMN_VALUE -------------------------------------------------------------------------------- 01/02/2009,01/09/2009,01/16/2009,01/23/2009,01/30/2009,02/06/2009,02/13/2009,02/ 20/2009,02/27/2009,03/06/2009,03/13/2009,03/20/2009,03/27/2009,04/03/2009,04/10/ 2009,04/17/2009,04/24/2009,05/01/2009,05/08/2009,05/15/2009,05/22/2009,05/29/200 9,06/05/2009,06/12/2009,06/19/2009,06/26/2009,07/03/2009,07/10/2009,07/17/2009,0 7/24/2009,07/31/2009,08/07/2009,08/14/2009,08/21/2009,08/28/2009,09/04/2009,09/1 1/2009,09/18/2009,09/25/2009,10/02/2009,10/09/2009,10/16/2009,10/23/2009,10/30/2 009,11/06/2009,11/13/2009,11/20/2009,11/27/2009,12/04/2009,12/11/2009,12/18/2009 ,12/25/2009 1 row selected.
-
HP Officejet J4580 all-in-One: where the printer cartridges are located
Where are the cartridges of printers that are located on the HP Oficejet J4580 all-in-One printer
The ink cartridges are located inside the printer. Go here... http://support.HP.com/us-en/product/HP-OfficeJet-J4000-all-in-one-printer-series/3645081/model/3645099/manuals download the User Guide and read page 10 for see where.
-
Hi all
I am new in the form of Oracle, I have a question,
in oracle from(10G) now I show an entire table, when I update a line, then in that same line, there is a column named as status, must got the update automatically with the value 'NEW '.
Can someone help me how to perform this task.
If any body knows then please reply as soon as POSSIBLE.
Thank you
Ashish
1003500 wrote:
Hi all
I am new in the form of Oracle, I have a question,
in oracle from(10G) now I show an entire table, when I update a line, then in that same line, there is a column named as status, must got the update automatically with the value 'NEW '.
Can someone help me how to perform this task.
If any body knows then please reply as soon as POSSIBLE.
Thank you
Ashish
Ashish
Try this
/ * write the following code in Post-Text-Item at the block level * /.
IF: System.Record_Status IN ("MODIFIED", "INSERT") THEN
: your_block_name.column_name: = 'NEW';
END IF;
Hamid
-
where two columns correspond to a single column
Hi in my where clause I need to match 2 to 1 columns
That is to say
session. CODE = 33
SN.code45 = 5555
So what I need is the session. CODE and SN.code45 (in collaboration with no space) = of
335555 = fromright (myString, len (myString)-2)
-
I despise scrolling bookmarks. I want to see them all at once in the columns.
How can I get rid of bookmarks ScrollBar? Is there an add-on? Mozilla manufacturers that allow an option?
(I do NOT mean "they keep scrolling when I want them to stop" or something like this.) I want to just see them all in columns.This extension could be close, but I have not tried myself: Multicolumn Bookmarks.
-
Different formulas for different rows in the column of the formula
Is this possible? If possible, how?Hello
I still don't think that the new version has something we have in FR.
We have only one formula per column of formulas in a web form to the difference in FR.Thank you
Sourabh.
Maybe you are looking for
-
We had to get a new computer and I want to copy bookmarks. Where were they stored?
Our old computer, desktop with Windows XP, wouldn't start, so we bought a new one (Windows 7). Extraction of data from the hard drive of the old computer. Is it possible that I can get the Firefox bookmarks? All information I found had to do with boo
-
What is the ConnectDLC toolbar and how do I get rid of him?
All of a sudden I get ConnectDLC toolbar as the default toolbar and can't get rid of it and also CONNECT is web page and will not go away by default. How can I get rid of these?
-
Model of VAIO Duo 11 SVD11225CXB &; Vaio Update
I bought this yesterday, and it works well, except that the Vaio Update fails to run correctly. When I run it, a web browser opens with a message saying "the Web site refused to view this page." VAIO Update then says: "Could not acquire information."
-
Pavilion dv6z-7000: universal serial bus drivers need
Hi, I need help to find the drivers for my Pavilion dv6z-7000 USB. I have Win7 64 bit. I just reinstalled my operating system on a new hard drive and I downloaded all the drivers available for my computer but none of them does not seem to work. Devi
-
Skype, a fatal error during installation.
I tried to update my version of Skype, after I was told it was necessary for Windows Live Messenger, but during the installation, I got a popup telling me a fatal error during installation. I've toured all over the web looking for a solution to this