Query to find unmatch records
i have 2 tables AHH and ASH. both contain similar columns. primary key on table ASH is based on account number and location id. I want a query to select rows from AHH that are not present in ASH (based on account number and location_id as primary key).
select distinct(h.AHH_N_ACCOUNT_NUM),h.AHH_V_LOCATION_ID from
AHH,ASH
where
(AHH_N_ACCOUNT_NUM <> ASH_N_ACCOUNT_NUM and
AHH_V_LOCATION_ID <> ASH_V_LOCATION_ID)
This query returns all rows in AHH. Can anyone provide me with correct query?
This is other way of doing it:
create table ahh (srl number (3),acc_num number(4),loca_id number(4));
insert into ahh values(1,100,1000);
insert into ahh values(1,200,2000);
insert into ahh values(1,300,3000);
insert into ahh values(1,400,4000);
create table ash (srl number(3),acc_num number(4),loca_id number(4));
insert into ash values(1,100,1000);
insert into ash values(1,200,2000);
select b.acc_num
,b.loca_id
,a.srl
from
ASH A,
AHH B
where
A.acc_num(+)=b.Acc_num
and a.loca_id(+)=b.loca_id
and a.srl is not null;
ACC_NUM LOCA_ID SRL
400 4000
300 3000
Similar Messages
-
Cfloop query only finding one record
I can't figure this out. My query is only finding one record
(in certain instances), but there are more records in the table. It
seems to the the problem when I use "LIKE". Everything prints fine
if I use equals.
Here's my code:
<cfparam name="form.kword" default="">
<cfparam name="form.fyear" default="2008">
<cfparam name="form.fnum" default="">
<cfparam name="form.titlew" default="">
<cfparam name="form.doctrak" default="">
<cfparam name="url.sterm" default="">
<cfparam name="url.fyear" default="">
<cfparam name="url.qtype" default="">
<!---Queries--->
<!---From FORM Query the forms table--->
<cfquery name="displayformresults"
datasource="#mydatasource#">
SELECT fstrkeywords, fstrdoctrak, fstrformnum, fstryear,
fstrtitle, fstrfilesize, fstrfiletype, fdtmrevdt, fblnfillin,
fstraddendum
FROM tblext_forms
WHERE fstrkeywords LIKE '%#form.kword#%' AND fstryear =
'#form.fyear#' AND fstrformnum LIKE '%#form.fnum#%' AND fstrtitle
LIKE '%#form.titlew#%' AND fstrdoctrak LIKE '%#form.doctrak#%'
ORDER BY fstrtitle, fstryear ASC
</cfquery>
<cfdump VAR="#displayformresults#"><!---Variable anyyeardisplay has been declared within a
<cfif> tag so where the necessary condition is not met it
means it would not been declared yet before you ask ColdFusion to
output it on the table... trouble!
So amend as below. If for any reason you need to put variable
nicefdtmrevdt within a conditional statement as well, just do the
same (as shown) --->
<cfloop query="displayformresults">
<cfif "#displayformresults.fstryear#" IS "">
<cfset #displayformsesults.fstryear# = "2008">
<cfelse>
<cfset anyyeardisplay = #displayformresults.fstryear#>
</cfif>
<cfset nicefdtmrevdt =
#DateFormat(#displayformresults.fdtmrevdt#, "mm-dd-yyyy")#>
<cfoutput>
<tr>
<td
class="fifteen">#displayformresults.fstrformnum#</td>
<td class="fifteen"><cfif isDefined
("anyyeardisplay")>
#anyyeardisplay#
</cfif></td>
<td class="fortyfive"><a href=""
title="#displayformresults.fstrdoctrak#">#displayformresults.fstrtitle#</a></td>
<td class="twentyfive"><cfif isDefined
("nicefdtmrevdt")>
#nicefdtmrevdt#
</cfif>
<br />
(#displayformresults.fstrfiletype#,
#displayformresults.fstrfilesize#)</td>
</tr>
</cfoutput> -
Acess 2010 - Finding unmatched records
I need to compare the contents of Table A & Table B.
Table A has 2 columns - Invoice Number and Vendor Number
Table B has 2 columns - Invoice Number and Vendor Number
Table A data
1, A
1, B
2, A
3, A
3, B
Table B data
1, A
1, C
2, A
3, A
3, C
My 'unmatched' result set should be:
1, C
3, C
How do I create an Access 2010 query that would give me these results?You can use the query below to find the different records between these two tables.
select * from B
where not exists
select * from A
where B.[Invoice Number]=A.[Invoice Number] and b.[Vendor Number]=a.[Vendor Number]
Create->Query Design->right the 'query1',click 'sql view' .And then copy the query into it.
Wind Zhang
TechNet Community Support -
Stuck on sql query to find parent records that have the same child records
Oracle 10gR2 Enterprise Edition.
Hi,
I'm trying to write some logic to look for records in a parent table, which have the exact same values in a child table.
This is part of a bigger query, but I'm stuck on this part for now, so I've mocked up some simplified tables below to capture the core of the
problem I'm stuck on.
Let say I've got a parent table Manager, a child table Employee and there's a many to many relationship between them.
The aptly named Join_Table handles the relationship between them. So one manager can manage many employees, one employee can be managed by
many managers.
I've a feeling this is stupidly easy, but I seem to be suffering from a bad bout of brain freeze today!
-- parent table
CREATE TABLE manager (
id number primary key,
name varchar2(100));
-- child table
CREATE TABLE employee (
id number primary key,
name varchar2(100));
-- link table
CREATE TABLE join_table (
manager_id NUMBER,
employee_id NUMBER,
CONSTRAINT join_table_pk PRIMARY KEY (manager_id, employee_id),
CONSTRAINT manager_fk FOREIGN KEY (manager_id) REFERENCES manager(id),
CONSTRAINT employee_fk FOREIGN KEY (employee_id) REFERENCES employee(id)
-- Insert some managers
INSERT INTO manager (id, name) VALUES (1, 'John');
INSERT INTO manager (id, name) VALUES (2, 'Bob');
INSERT INTO manager (id, name) VALUES (3, 'Mary');
INSERT INTO manager (id, name) VALUES (4, 'Sue');
INSERT INTO manager (id, name) VALUES (5, 'Alan');
INSERT INTO manager (id, name) VALUES (6, 'Mike');
-- Insert some employees
INSERT INTO employee (id, name) VALUES (101, 'Paul');
INSERT INTO employee (id, name) VALUES (102, 'Simon');
INSERT INTO employee (id, name) VALUES (103, 'Ken');
INSERT INTO employee (id, name) VALUES (104, 'Kevin');
INSERT INTO employee (id, name) VALUES (105, 'Jack');
INSERT INTO employee (id, name) VALUES (106, 'Jennifer');
INSERT INTO employee (id, name) VALUES (107, 'Tim');
-- Insert the links
-- John manages Paul, Simon, Ken
INSERT INTO join_table (manager_id, employee_id) VALUES (1, 101);
INSERT INTO join_table (manager_id, employee_id) VALUES (1, 102);
INSERT INTO join_table (manager_id, employee_id) VALUES (1, 103);
-- Bob manages Paul, Simon, Kevin, Jack
INSERT INTO join_table (manager_id, employee_id) VALUES (2, 101);
INSERT INTO join_table (manager_id, employee_id) VALUES (2, 102);
INSERT INTO join_table (manager_id, employee_id) VALUES (2, 104);
INSERT INTO join_table (manager_id, employee_id) VALUES (2, 105);
-- Mary manages Jennifer, Tim
INSERT INTO join_table (manager_id, employee_id) VALUES (3, 106);
INSERT INTO join_table (manager_id, employee_id) VALUES (3, 107);
-- Sue manages Jennifer, Tim
INSERT INTO join_table (manager_id, employee_id) VALUES (4, 106);
INSERT INTO join_table (manager_id, employee_id) VALUES (4, 107);
-- Alan manages Paul, Simon, Ken, Jennifer, Tim
INSERT INTO join_table (manager_id, employee_id) VALUES (5, 101);
INSERT INTO join_table (manager_id, employee_id) VALUES (5, 102);
INSERT INTO join_table (manager_id, employee_id) VALUES (5, 103);
INSERT INTO join_table (manager_id, employee_id) VALUES (5, 106);
INSERT INTO join_table (manager_id, employee_id) VALUES (5, 107);
-- Mike manages Paul, Simon, Ken
INSERT INTO join_table (manager_id, employee_id) VALUES (6, 101);
INSERT INTO join_table (manager_id, employee_id) VALUES (6, 102);
INSERT INTO join_table (manager_id, employee_id) VALUES (6, 103);
-- For sanity
CREATE UNIQUE INDEX employee_name_uidx ON employee(name);So if I'm querying for manager John, I want to find the other managers who manage the exact same list of employees.
Answer should be Mike.
If I'm querying for manager Mary, answer should be Sue.
This query will give me the list of managers who manage some of the same employees as John, but not the exact same employees...
SELECT DISTINCT m.name AS manager
FROM manager m, join_table jt, employee e
WHERE m.id = jt.manager_id
AND jt.employee_id = e.id
AND e.id IN (
SELECT e.id
FROM manager m, join_table jt, employee e
WHERE m.id = jt.manager_id
AND jt.employee_id = e.id
AND m.name = 'John')
ORDER BY 1;I thought about using set operations to find managers whose list of employees minus my employees is null and where my employees minus their list of employees is null. But surely there's a simpler more elegant way.
Any ideas?
Btw, I need to run this as a batch job against tables with >20 million rows so query efficiency is key.What about...
WITH manager_list AS
SELECT name,
LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
FROM (SELECT m.name,
e.id,
ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
FROM manager m,
join_table jt,
employee e
WHERE m.id = jt.manager_id
AND jt.employee_id = e.id
AND m.name = :P_MANAGER)
GROUP BY name
CONNECT BY prev = PRIOR curr AND name = PRIOR name
START WITH curr = 1
), all_list AS
SELECT name,
LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
FROM (SELECT m.name,
e.id,
ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
FROM manager m,
join_table jt,
employee e
WHERE m.id = jt.manager_id
AND jt.employee_id = e.id)
GROUP BY name
CONNECT BY prev = PRIOR curr AND name = PRIOR name
START WITH curr = 1
SELECT a.*
FROM manager_list m,
all_list a
WHERE m.employees = a.employeesWould be easier in 11g, but I don't have an installation here so this is based on 10g.
Cheers
Ben -
Need sql query to find ten records in sequential manner
Plz help me
I need to have ten records on my page. at the bottom of the page, i want to dispaly the number of pages that have records , just as a google page shows at the bottom. if the moves user moves to the next page , the next ten records must be displayed. suppose the user selects and clicks 5th page then the records on that page are displayed.How can i write the sql query corresponding to this specificationi don't want all records to be fetched at the same time and put on the server, rather whenever the page is opened , the corresponding records are fetched and displayedHi
Maybe you should use a CachedRowSet.
Look this:
http://developer.java.sun.com/developer/technicalArticles/javaserverpages/cachedrowset/
This page has a example that will help you. -
How to find unmatched records in huge tables
Hi,
I want to find out the faster approach, to find records in two tables which do not match.
To make it clear, lets say we have two tables.
table_1(col1 number, col2 varchar2(20), ....other columns)
and
table_2(col3 number, col4 varchar2(20), ....other columns)
col1, col2 from table_1 corresponds to col3, col4 of table_2.
If a record in table_1 does not exists in table_2 or if one of the column has different value, I want to find all such records.
Being Oracle developer, I can easily find that using "outer join" or using "exists".
But want to find out the fastest way, as those table has millions of records.
Maybe using segment or something like that...
Any suggestions?If "the" fastes way would exist oracle would not implement the others.
You will have to test it. The easiest way is to use set autotrace on in sqlplus and compere the consistent gets of both statements (by the way: there is also the MINUS operator with also leads to an outer join but is easier to read).
Dim -
Finding unmatched records between two tables
Hi,
Suppose there are two tables - A and B and they have a couple of common key fields. I want to select those records from A which do not have a matching record in B. What will be most efficient way to do that?
Thank you.Hey,
Look at this link .......... i think this may help you a bit to achieve ur requirement
http://help.sap.com/saphelp_470/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
Comparing Internal Tables: -
Internal tables can be compared with the operands that are used to compare other data objects. The most important criteria for comparing the internal table are the number of lines they contain. The larger the number of lines, the larger it is for comparisons. If the both the internal tables have same number of lines, then they are compared line by line. The operands used for comparisons are LE, LT, GE, GT, EQ, NE.
Except for EQ, the comparison stops at the first pair of components that identifies the condition false. -
Query to find duplicate records (Urgent!!!!)
Hi,
I have a to load data from a staging table to base table but I dont want to load data already present in the base table. Criteria to identify the duplicate data is thorugh a field say v_id and status_flag. If these two are the same in both staging and base table then that record must be rejected as a duplicate record.
Kindly help me with the SQL which i need to use in a Procedure.
ThanksHello
Another alternative would be to use MINUS if the table structures match:
--Source rows the first 5 are in the destination table
SQL> select * from dt_test_src;
OBJECT_ID OBJECT_NAME
101081 /1005bd30_LnkdConstant
90723 /10076b23_OraCustomDatumClosur
97393 /103a2e73_DefaultEditorKitEndP
106075 /1048734f_DefaultFolder
93337 /10501902_BasicFileChooserUINe
93013 /106faabc_BasicTreeUIKeyHandle
94929 /10744837_ObjectStreamClass2
100681 /1079c94d_NumberConstantData
90909 /10804ae7_Constants
102543 /108343f6_MultiColorChooserUI
92413 /10845320_TypeMapImpl
89593 /10948dc3_PermissionImpl
102545 /1095ce9b_MultiComboBoxUI
98065 /109cbb8e_SpanShapeRendererSim
103855 /10a45bfe_ProfilePrinterErrors
102145 /10a793fd_LocaleElements_iw
98955 /10b74838_SecurityManagerImpl
103841 /10c906a0_ProfilePrinterErrors
90259 /10dcd7b1_ProducerConsumerProd
100671 /10e48aa3_StringExpressionCons
20 rows selected.
Elapsed: 00:00:00.00
--Destination table contents
SQL> select * from dt_test_dest
2 /
OBJECT_ID OBJECT_NAME
101081 /1005bd30_LnkdConstant
90723 /10076b23_OraCustomDatumClosur
97393 /103a2e73_DefaultEditorKitEndP
106075 /1048734f_DefaultFolder
93337 /10501902_BasicFileChooserUINe
Elapsed: 00:00:00.00
--try inserting everything which will fail because of the duplicates
SQL> insert into dt_test_dest select * from dt_test_src;
insert into dt_test_dest select * from dt_test_src
ERROR at line 1:
ORA-00001: unique constraint (CHIPSDEVDL1.DT_TEST_PK) violated
Elapsed: 00:00:00.00
--now use the minus operator to "subtract" rows from the source set that are already in the destination set
SQL> insert into dt_test_dest select * from dt_test_src MINUS select * from dt_test_dest;
15 rows created.
Elapsed: 00:00:00.00
SQL> select * from dt_test_dest;
OBJECT_ID OBJECT_NAME
101081 /1005bd30_LnkdConstant
90723 /10076b23_OraCustomDatumClosur
97393 /103a2e73_DefaultEditorKitEndP
106075 /1048734f_DefaultFolder
93337 /10501902_BasicFileChooserUINe
89593 /10948dc3_PermissionImpl
90259 /10dcd7b1_ProducerConsumerProd
90909 /10804ae7_Constants
92413 /10845320_TypeMapImpl
93013 /106faabc_BasicTreeUIKeyHandle
94929 /10744837_ObjectStreamClass2
98065 /109cbb8e_SpanShapeRendererSim
98955 /10b74838_SecurityManagerImpl
100671 /10e48aa3_StringExpressionCons
100681 /1079c94d_NumberConstantData
102145 /10a793fd_LocaleElements_iw
102543 /108343f6_MultiColorChooserUI
102545 /1095ce9b_MultiComboBoxUI
103841 /10c906a0_ProfilePrinterErrors
103855 /10a45bfe_ProfilePrinterErrors
20 rows selected.You could use that in conjunction with the merge statement to exclude all trully duplicated rows and then update any rows that match on the id but have different statuses:
MERGE INTO dest_table dst
USING( SELECT
v_id,
col1,
col2 etc
FROM
staging_table
MINUS
SELECT
v_id,
col1,
col2 etc
FROM
destination_table
) stg
ON
(dts.v_id = stg.v_id)
WHEN MATCHED THEN....HTH -
Analytic query to select next record
Hi all,
I would like to query the below two table match to ouput.
1.dev_wt 2.dev_map 3.Output Result
To help more clearance please see this image link : http://lh6.ggpht.com/_xL6eBqjW6Yo/TEqnSvlF_FI/AAAAAAAAB0U/i2sclnnaj6g/Untitled-3.jpg
1. dev_wt
PMS_COMP PMS_I PMS_PERF_D PMS_WT PMS_CREATION_D
BBOARD GICEQGROSS 04/01/2001 30 04/05/2001
BBOARD GICST_B 04/01/2001 5 04/05/2001
BBOARD SBGS_B 04/01/2001 65 04/05/2001
BBOARD GICEQGROSS 04/11/2001 30 04/15/2001
BBOARD GICST_B 04/11/2001 5 04/15/2001
BBOARD SBGS_B 04/11/2001 65 04/15/20012. dev_map
GS_CODE GS_I_CODE GS_I_ID MD_ID GS_START_DT GS_END_DT
GICEQGROSS CIWL 304 15 01/04/1998 31/03/2004
GICEQGROSS CIWL 304 2 01/04/2004 31/03/9998
GICST_B GICST_B 3707 15 01/04/2000 31/12/9998
SBGS_B SBGS_B 2231 15 01/04/1992 30/09/2003
SBGS_B SBGS_B 564 15 01/10/2003 31/12/9998I would like to match PMS_I = GS_CODE to retrieve GS_I_CODE and using analytic
query to find next record.
Because I need to select GICEQGROSS record of PMS_PERF_D date and next
GICEQGROSS record of PMS_PERF_D from dev_wt table and put GS_WT_FR and GS_WT_TO of Output result.
***Date is change to YYYYMMDD format
***PMS_WT is devided by 100
*3. Output Result*
GS_I_ID PMS_COMP GS_I_CODE GS_WT_FR GS_WT_TO GS_I_CALC
304 BBOARD CIWL 20010401 20010410 0.3
3707 BBOARD GICST_B 20010401 20010410 0.05
5209 BBOARD SBGS_B 20010401 20010410 0.65PMS_COMP is from dev_wt table
GS_I_CODE is from dev_map table join with dev_wt
GS_WT_FR is from dev_wt table of GS_START_DT
GS_WT_TO is from dev_wt table of next record GS_START_DT where PMS_I ='GICEQGROSS'
Now my difficulty is to select next record of PMS_PERF_D using analytic query. Below
is my query...
SELECT GS_I_ID, PMS_COMP, GS_I_CODE, GS_WT_FR, GS_WT_TO, GS_I_CALC
FROM dev_wt (
SELECT lead(PMS_PERF_D) over(partition by PMS_I order by PMS_PERF_D) as GS_WT_TO
FROM dev_wt where PMS_I ='GICEQGROSS')
left join dev_map on PMS_I = GS_CODE ;Thanks
Edited by: WinZone on Jul 24, 2010 4:46 PM
Edited by: WinZone on Jul 24, 2010 4:50 PMHi,
This query should be fine:
SELECT DISTINCT t2.gs_i_id, pms_comp, t2.gs_i_code,
TO_CHAR
(MIN (pms_perf_d) OVER (PARTITION BY pms_comp, pms_i),
'yyyymmdd'
) gs_wt_fr,
TO_CHAR
(MAX (pms_perf_d) OVER (PARTITION BY pms_comp, pms_i) - 1,
'yyyymmdd'
) gs_wt_to,
pms_wt / 100 gs_i_calc
FROM dev_wt t1, dev_map t2
WHERE t2.gs_code = t1.pms_iREM Same remark as odie: should be "2231" instead ... -
Query to find the latest record with respect to the current status
Dear gurus
I have the following data in a table
Customernum
bkcode
reqtdate
Prevstat
currstat
The data will be like this
CustomerNum bkcode reqdate prevstat currstat
5900 1 03-Aug-12 0 1
5900 1 06-Aug-12 1 0
5900 5 22-Jun-12 0 1
If a customer has an issue to solved, a record is added with bkcode , register date and currstat will be 1
If the issue is resolved for the bookingcode,a new record is added, the currentstatus will become 0. and prev stat will show 1. Row no 1 and 2 reflects this case
If this table is queried for finding the unresolved issues. the output should be only the Last row of the above example. since issue with bookingcode 1 has been resolved
I have trying hard to get this thing confused what to use Lead or Max
Kindly guide meHi,
one way here:
WITH mytable(CustomerNum, bkcode, reqdate, prevstat, currstat)
AS
SELECT 5900, 1, TO_DATE('03-Aug-12', 'DD-Mon-YY'), 0, 1 FROM DUAL UNION ALL
SELECT 5900, 1, TO_DATE('06-Aug-12', 'DD-Mon-YY'), 1, 0 FROM DUAL UNION ALL
SELECT 5900, 5, TO_DATE('22-Jun-12', 'DD-Mon-YY'), 0, 1 FROM DUAL
SELECT CustomerNum, bkcode, reqdate, prevstat, currstat
FROM (SELECT a.*
, ROW_NUMBER() OVER (PARTITION BY CustomerNum, bkcode
ORDER BY reqdate DESC) AS rn
FROM mytable a
WHERE rn=1
AND currstat=1;
CUSTOMERNUM BKCODE REQDATE PREVSTAT CURRSTAT
5900 5 22-JUN-12 0 1Regards.
Al
Edited by: Alberto Faenza on Dec 18, 2012 5:23 PM
Changed again!! Previous logic was wrong -
Help with Finding Duplicate records Query
HI,
I am trying to write a query that will find duplicate records/cases.
This query will be used in a report.
So, here are the requirements:
I need to find duplicate cases/records based on the following fields:
DOB, DOCKET, SENT_DATEI was able to do that with the following query. The query below is able to give me all duplicate records based on the Criteria above
SELECT DEF.BIRTH_DATE DOB,
S.DOCKET DOCKET,
S.SENT_VIO_DATE SENT_DATE, COUNT(*)
FROM SENTENCES S,
DEFENDANTS DEF
WHERE S.DEF_ID = DEF.DEF_ID
AND S.CASE_TYPE_CODE = 10
GROUP BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE
HAVING COUNT(*) > 1;
//I AM GOING TO CALL THIS QUERY 'X'Now, the information to be displayed on the report: defendants Name, DOB, District, Docket, Def Num, Sent Date, and PACTS Num if possible.
The problem that I need help on is how to combine those queries together (what I mean is a sub query). the 'X' query returns multiple values. please have a look at the comments on the query below to see what I'm trying to achieve.
here is the main query:
SELECT INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
DEF.BIRTH_DATE DOB,
TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
S.DOCKET DOCKET,
S.DEF_NUM DEF_NUM,
S.SENT_VIO_DATE SENT_DATE,
DEF.PACTS_ID PACTS_NUM
FROM USSC_CASES.DEFENDANTS DEF,
USSC_CASES.SENTENCES S,
LOOKUP.DISTRICTS DIST
WHERE DEF.DEF_ID = S.DEF_ID
AND S.DIST_ID = DIST.USSC_DISTRICT_ID
AND S.CASE_TYPE_CODE = 10
AND S.USSC_ID IS NOT NULL
AND // what i'm trying to do is: DOB, DOCKET, SENT_DATE IN ('X' QUERY), is this possible ??
ORDER BY DEFENDANT_NAME; thanks in advance.
I am using Oracle 11g, and sql developer.
if my approach doesn't work, is there a better approach ?
Edited by: Rooney on Jul 11, 2012 3:50 PMIf I got it right, you want to join table USSC_CASES.DEFENDANTS to duplicate rows in USSC_CASES. If so:
SELECT INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
DEF.BIRTH_DATE DOB,
TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
S.DOCKET DOCKET,
S.DEF_NUM DEF_NUM,
S.SENT_VIO_DATE SENT_DATE,
DEF.PACTS_ID PACTS_NUM
FROM USSC_CASES.DEFENDANTS DEF,
SELECT *
FROM (
SELECT S.*,
COUNT(*) OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE) CNT
FROM USSC_CASES.SENTENCES S
WHERE CNT > 1
) S,
LOOKUP.DISTRICTS DIST
WHERE DEF.DEF_ID = S.DEF_ID
AND S.DIST_ID = DIST.USSC_DISTRICT_ID
AND S.CASE_TYPE_CODE = 10
AND S.USSC_ID IS NOT NULL
ORDER BY DEFENDANT_NAME;If you want to exclude duplicates from the query and do not care which row out of duplicate rows to choose:
SELECT INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
DEF.BIRTH_DATE DOB,
TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
S.DOCKET DOCKET,
S.DEF_NUM DEF_NUM,
S.SENT_VIO_DATE SENT_DATE,
DEF.PACTS_ID PACTS_NUM
FROM USSC_CASES.DEFENDANTS DEF,
SELECT *
FROM (
SELECT S.*,
ROW_NUMBER() OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE ORDER BY 1) RN
FROM USSC_CASES.SENTENCES S
WHERE RN = 1
) S,
LOOKUP.DISTRICTS DIST
WHERE DEF.DEF_ID = S.DEF_ID
AND S.DIST_ID = DIST.USSC_DISTRICT_ID
AND S.CASE_TYPE_CODE = 10
AND S.USSC_ID IS NOT NULL
ORDER BY DEFENDANT_NAME;SY. -
Query to find records with more than 2 decimal places
I have written the below query to find records with more than 2 decimal places, but it is returning records with decimal places 1 & 2.
The datatype of the AMT column is NUMBER (without any precision).
SELECT amt FROM amount_table
WHERE substr(amt, instr(amt, '.')) LIKE '.%'
AND length(substr(amt, instr(amt, '.') + 1)) > 2Output:-
AMT
*41591.1*
*275684.82*
*64491.59*
*3320.01*
*6273.68*
*27814.18*
*30326.79*
131.8413635
162.5352898
208.5203816
8863.314632
22551.27856
74.716992
890.0158441
2622.299682
831.6683841
*1743.14*
2328.195877
3132.453438
5159.827334
3.236234727
37.784
ThanksOracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
create table amount_table
LINE_NUMBER NUMBER not null,
FEE_AMT NUMBER not null
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (60208, 41591.1);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (60213, 275684.82);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (60238, 64491.59);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (63026, 3320.01);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (59906, 6273.68);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (83111, 27814.18);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (83114, 30326.79);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112395, 131.8413634682);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112399, 162.5352898104);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112402, 208.5203815738);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112403, 8863.3146321954);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112406, 22551.2785551322);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112407, 74.716992);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112410, 890.015844079);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112411, 2622.2996817048);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112414, 831.6683840698);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112415, 1743.14);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112418, 2328.1958771886);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112419, 3132.4534379886);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112422, 5159.8273341686);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112423, 3.2362347266);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112426, 37.784);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112427, 198.7423503696);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112430, 0.7220848332);
insert into amount_table (LINE_NUMBER, FEE_AMT)
values (2112433, 12.4149375254); -
How to find the unmatched records between the two tables?
We have to tables in SQL Server database.
But unable to find the unmatched record betwwen these two tables.
There 12 records are unmatched. But unable to get those records.
I am using the below sql:
select c1,c2,c3,c4,c5,c6 from Table1
except select c1,c2,c3,c4,c5,c6 from Table2
Please help. Thanks in advance.Hi knra,
Please try the following codes:
select c1,c2,c3,c4,c5,c6 from Table1 t1
where not exists
(select * from Table2 t2
where t1.c1= t2.c1
and t1.c2= t2.c2
and t1.c3= t2.c3
and t1.c4= t2.c4
and t1.c5= t2.c5
and t1.c6= t2.c6)
Best Regards,
Allen Li
Allen Li
TechNet Community Support
This is what I would've said, but it would make life much easier for you if you have a reference or ID for each entry, this is why we use keys. -
Hello
We'd like to make a "find unmatched query" (similar to Microsoft Access); so, we created an outer join via Discoverer Administrator, and in Discoverer Desktop we tried to include a condition were only the rows with null value for a field in the outer joined table were shown.
The problem is that Discoverer also uses "(+)" for the null condition:
outerjoined_field(+) is null
This is why we are not getting the expected result.
Even if i import the sql withouth the (+) for the null condition, Discoverer adds the (+)
Is there a way to make a "find unmatched query"? (get all the information in table A where A.ID doesn't exist in B.ID)
Thanks in advance
More details:
1. Version: 9.0.2
2. Query generated by Discoverer:
SELECT COUNT(RTR_LKP_CLIENTE.ID_CLIENTE), COUNT(RTR_MAT_MAESTRO_POL_2.DES_POLIZA)
FROM RTR_ADMIN.RTR_LKP_CLIENTE RTR_LKP_CLIENTE, RTR_ADMIN.RTR_MAT_MAESTRO_POL_2 RTR_MAT_MAESTRO_POL_2
WHERE ( ( RTR_MAT_MAESTRO_POL_2.DES_POLIZA = RTR_LKP_CLIENTE.DES_POLIZA(+) ) ) AND ( RTR_LKP_CLIENTE.ID_CLIENTE(+) IS NULL ) AND ( RTR_MAT_MAESTRO_POL_2.DES_PREF_DIVISION = 'C1' )
3. Desired query:
SELECT COUNT(RTR_LKP_CLIENTE.ID_CLIENTE), COUNT(RTR_MAT_MAESTRO_POL_2.DES_POLIZA)
FROM RTR_ADMIN.RTR_LKP_CLIENTE RTR_LKP_CLIENTE, RTR_ADMIN.RTR_MAT_MAESTRO_POL_2 RTR_MAT_MAESTRO_POL_2
WHERE ( ( RTR_MAT_MAESTRO_POL_2.DES_POLIZA = RTR_LKP_CLIENTE.DES_POLIZA(+) ) ) AND ( RTR_LKP_CLIENTE.ID_CLIENTE IS NULL ) AND ( RTR_MAT_MAESTRO_POL_2.DES_PREF_DIVISION = 'C1' )Ok, thank you very much
I didn't know that Discoverer used (+) only in some cases; using "field is null" is generated as "field (+) is null", but using OR is a good alternative, also using "field in (null)" worked fine, although i find it a little tricky.
Thanks again, bye -
Query to find today's records?
Hello,
I am working on a little CF project and I need to find all
records that have today's date (time would also be included on the
field, in case that is relevant) What query would you use to
retrieve all records entered "today"? Thank you!No dateValue () has been part of Microsoft Access for a while
now. What version of Access are you using?
Are you using Access as a front end to MS SQL?
Anyway, there is something else going on.
Turn on all debugging options and post the EXACT, FULL, error
message here.
Maybe you are looking for
-
G50 won't switch to external display
I've updated the Intel video driver to the latest, 6.14.10.4277, but I still can't get my external display to work with my G40 through the external VGA connector. The display works with my R40, but not with my G40. It doesn't even show anything dur
-
Adding Covers to EPUBS via InDesign?
Does anyone know how to add covers to Epubs via Indesign? Ultimatly, I want my finished product to be like the Winnie the Pooh book so that ANYONE who downloads the epub will have the cover appearing in the ibook bookcase in the Ipad, nook, and Kindl
-
All invisible items visible now - What to do?
Greetings everyone, All of a sudden all the invisible items at the root level of my HD have become visible, stuff like "bin", "sbin", "Volumes", "etc", "dev" and so on... are now visible, my guess is they are system files, and not to be tampered with
-
Bar Chart - No Solid Colors!
Post Author: xedious CA Forum: Charts and Graphs How do I format a bar chart so that ALL the bars show up as black and white patterns? In design mode, I can see three 'risers' that I can set the pattern and color on, but when the report runs and the
-
i have a problem when iam trying to call a report in form error frm-41312 occurs how can i get rid from this i have used several techniques . iam using oracle9i