Simple join question - my query is returning unwanted rows ...
My SQL select is returning more rows that I want it to return. The table that I'm joining on has multiple rows per CaseId, and I'm only interested in getting one...
table1
CaseId column1 column2
8 elmo foz
9 foo bar
10 fuz baz
11 fuy bay
table2
CaseId Seq column8 column9
8 1 choc strawberry
9 1 banana orange
9 2 do re
10 1 me fa
So a SQL select like:
select t1.CaseId, t1.column1, t1.column2, t2.column8
FROM table1 t1 LEFT OUTER JOIN table2 t2
ON t1.CaseId = t2.CaseId
returns data like:
t1.CaseId t1.column1 t1.column2 t2.column8
8 elmo foz choc
9 foo bar banana
9 fuz baz do
I want the SQL select to return only one row for each row that’s in table1; CaseId of 9 should have only one row in the SQL select results.
The table2 has multiple rows, because of the Seq column. How can I formulate the SQL select to join on table2 using CaseId and the max Seq value?
Thank you!
Untested..
with t1 AS
(SELECT *
FROM (SELECT table2.*,
ROW_NUMBER ()
OVER (PARTITION BY caseid ORDER BY seq DESC)
r
FROM table2)
WHERE r = 1)
SELECT t1.CaseId,
t1.column1,
t1.column2,
t2.column8
FROM table1 t1 LEFT OUTER JOIN t1 t2 ON t1.CaseId = t2.CaseId;OUTPUT:
CASEID COLUMN1 COLUMN2 COLUMN8
8 elmo foz choc
9 foo bar do
10 fuz baz me
11 fuy bay Cheers,
Manik.
Similar Messages
-
Query to return ALL rows even those with zero counts
Hi,
The following query will return only those rows that have a non zero count value:
select c.id, a.name, count(*) as XYZ from CON c, CUST a
where c.help !='1' and (c.id = a.id) group by c.id, a.name order by c.id;
The results are:
1 ME 3
3 YOU 4
What i want is to return all rows in CUST and the count, XYZ, that correspond to each row in CUST that matches the whare condition above, even if the count is zero.
ie
1 ME 3
2 WE 0
3 YOU 4
Can this be done?You may want to get the counts then do the outer join. If you simply count with an outer join you will get 1 for 'WE' because there is a row in the cust table with 'WE'. This may work for you;
with
cust as (
select 1 id, 'ME' name from dual union all
select 2 id, 'YOU' name from dual union all
select 3 id, 'WE' name from dual),
con as (
select 1 id, '2' help from dual union all
select 1 id, '2' help from dual union all
select 1 id, '2' help from dual union all
select 2 id, '2' help from dual union all
select 2 id, '2' help from dual union all
select 2 id, '2' help from dual union all
select 2 id, '2' help from dual)
-- end of test data
select a.id, a.name, nvl(c.cnt,0) xyz
from cust a,
(select id, help, count(*) cnt
from con
where help !='1'
group by id, help) c
where a.id = c.id(+) -
25 minutes to run a query then returns no rows
Hi,
Just wondered if someone could explain why the following query takes 25 minutes to run and then returns no rows. Sorry if this seems obvious to you but I'm still learning Oracle and I'd really appreciate an answer.
(this is a trace taken through the application so it shows the bind variables - this much I've learnt! )
Thanks
Mark
Select /*+ INDEX(DAE_ GACCENTRYD_DAE0) */ DAE_.ROWID, DAE_.*
From IDIS.GACCENTRYD DAE_ Where DAE_.ACC_0 = :1
Order by DAE_.TYP_0,DAE_.NUM_0,DAE_.LIG_0
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.01 0 0 0 0
Fetch 1 30.32 1528.03 192062 354581 0 0
total 3 30.32 1528.04 192062 354581 0 0
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 30
Rows Row Source Operation
0 TABLE ACCESS BY INDEX ROWID GACCENTRYD
3792690 INDEX FULL SCAN (object id 189011)Select /*+ INDEX(DAE_ GACCENTRYD_DAE0) */ <-- check what are the columns involved in this index
DAE_.ROWID, DAE_.*
From IDIS.GACCENTRYD DAE_
Where DAE_.ACC_0 = :1
Order by DAE_.TYP_0,DAE_.NUM_0,DAE_.LIG_0
1. check what are your columns in your index GACCENTRYD_DAE0
2. the columns involved on your index GACCENTRYD_DAE0 should also be used in your WHERE predicates
3. if no columns are used in your WHERE predicates that are involved in your index GACCENTRYD_DAE0 try to removed the hint -
Hi all,
I've a requirement where in I've to get multiple rows from a query.
The resultset should be something like this:
SELECT A
FROM dual;
A
1
2
3
4
5
6
7
8
9
10
Thanks in anticipation
RK RajuI'm not completely certain I understand the question. Just in case you're asking for something as simple as this ...
select rownum from all_objects where rownum <= 10;You didn't say what version you were using either (shame on you). You could use a collection or a pipeline depending on your version ...
create or replace type ttab_number is table of number;
create or replace function f_collection
return ttab_number is
tab_number ttab_number := ttab_number();
begin
for i in 1 .. 10 loop
tab_number.extend;
tab_number(tab_number.count) := i;
end loop;
return tab_number;
end f_collection;
select *
from table(f_collection)
create or replace function f_pipeline
return ttab_number
pipelined is
begin
for i in 1 .. 10 loop
pipe row(i);
end loop;
return;
end f_pipeline;
show errors
select *
from table(f_pipeline) -
Query to return separate rows for date range including NULLs
I'm trying to write a query that will return all customers from table 1. Table 1 also provides a start date and an end date that may be different for different customers. Left join with Table 2 provides all matches and NULL if NO matches.
If there is any match at all, I do not get the NULLs for other dates. There should be a match for each date from start to end. How can I write the code so that my return will loop thru each date and provide the match or NULL?Sorry. I am somewhat new to this and am not sure what you are requesting. I receive a return of all customers with the code below but if customer 1 has a start date of 1/1/15 and a stop date of 1/5/15 and a document exists for 1/1/15 and 1/3/15
I do not receive the rows with NUL for 1/2/15, 1/4/15, and 1/5/15 which is what I'm trying to accomplish. If there is no match at all, I only receive the one row with NULL and I would like to see a row for each date from start to stop.
SELECT T1.IDNumber,T1.StartDate,T1.StopDate,T3.SignDateTime
FROM
Table1 T1
INNER
JOIN Table2
T2
ON
T1.CustID
= T2.CustID
LEFT
JOIN Table3
T3
ON
T1.CustID
= T3.CustID
WHERE
T1.StartDate
> '2015-01-20 00:00:00.000'
AND
(T3.ReportID
IN ('DOC1',
'DOC2',
'DOC3') OR
T3.ReportID
IS NULL)
AND
T2.YesNo
= 'Y' -
Query not returning any rows?
hi experts,
My query running long but not returning any result. i have data , no locks on the tables.
i have bigger ( hardware ) database on different server , where I can get results with same query.
Can you tell me what are the DB settings i have to look at to resolve this issue?
( any sql query that can monitor these parameters ?)
(the tabels involved in this query has 33milliions, 2millions, 7 milllions )
Thanks ..
Edited by: 642877 on Sep 21, 2011 6:46 PMOracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production"
TNS for Solaris: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
==========================================================
Plan hash value: 3185710999
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 3 | 423 | 24592 (2)| 00:05:45 | | |
| 1 | HASH GROUP BY | | 3 | 423 | 24592 (2)| 00:05:45 | | |
| 2 | NESTED LOOPS | | | | | | | |
| 3 | NESTED LOOPS | | 3 | 423 | 24591 (2)| 00:05:45 | | |
| 4 | NESTED LOOPS | | 3 | 345 | 24585 (2)| 00:05:45 | | |
| 5 | NESTED LOOPS | | 1 | 84 | 21916 (2)| 00:05:07 | | |
| 6 | NESTED LOOPS | | 1 | 67 | 21915 (2)| 00:05:07 | | |
| 7 | PARTITION LIST ALL | | 2 | 60 | 21913 (2)| 00:05:07 | 1 | 11 |
|* 8 | TABLE ACCESS FULL | ART_CRDT_ACCT_FACT | 2 | 60 | 21913 (2)| 00:05:07 | 1 | 11 |
|* 9 | TABLE ACCESS BY INDEX ROWID| ART_PRTFOL_GRP_DIM | 1 | 37 | 1 (0)| 00:00:01 | | |
|* 10 | INDEX UNIQUE SCAN | ART_PRTFOL_GRP_DIM_INDEX1 | 1 | | 0 (0)| 00:00:01 | | |
| 11 | TABLE ACCESS BY INDEX ROWID | W_MONTH_D | 1 | 17 | 1 (0)| 00:00:01 | | |
|* 12 | INDEX UNIQUE SCAN | UQ_W_MONTH_D | 1 | | 0 (0)| 00:00:01 | | |
| 13 | PARTITION LIST ITERATOR | | 3 | 93 | 2669 (2)| 00:00:38 | KEY | KEY |
|* 14 | TABLE ACCESS FULL | ACCT_CLTRL_RLTNP | 3 | 93 | 2669 (2)| 00:00:38 | KEY | KEY |
|* 15 | INDEX UNIQUE SCAN | UQ_ART_CLTRL_DIM | 1 | | 1 (0)| 00:00:01 | | |
| 16 | TABLE ACCESS BY INDEX ROWID | CLTRL_DIM | 1 | 26 | 2 (0)| 00:00:01 | | |
------------------------------------------------------------------------------------------------------------------------------- -
SQL query that returns exclusive rows from groups
I'm using modified scott/tiger data for this.
I've got two tables
DEPT_X
DEPTNO DNAME LOC CODE_ID SUB_DEPTNO
10 ACCOUNTING NEW YORK 111 101
10 SALES ATWN 111 102
10 SALES BTWN 112 103
20 RESEARCH DALLAS 111 201
20 RESEARCH CTWN 111 202
30 SALES CHICAGO 111 301
40 OPERATIONS BOSTON 112 401and
BI_PD
CODE_ID PD_TYPE BI_TYPE
111 -1
112 -1 I want to write a query that joins the code_ids of the two tables and lists out either only the records from DEPT_X who's code_ids have a -1 in the PD_TYPE(112) column and none of the code_ids that have a -1 in the BI_TYPE(111) column for each department or if that department has code_ids for the BI_TYPE (111), list out those rows. So for Deptno 10 you'll only get the row with SUB_DEPTNO = 103. But if for that DEPTNO= 20 you'll get the rows for both SUB_DEPTNO = 201 and 202.
So the result should look like
DEPTNO SUB_DEPTNO
10 103
20 201
20 202
30 301.
Basically I just want rows from each department that have code_ids = 111 not to show up if there are code_ids = 112.
What is the query to do this?
Message was edited by:
user623359
Message was edited by:
user623359
Message was edited by:
user623359
Message was edited by:
user623359
Message was edited by:
user623359One way could be:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> with dept_x as (
2 select 10 deptno, 'ACCOUNTING' dname, 'NEW YORK' loc, 111 code_id, 101 sub_deptno from dual
union all
3 select 10, 'SALES', 'ATWN', 111, 102 from dual union all
4 select 10, 'SALES', 'BTWN', 112, 103 from dual union all
5 select 20, 'RESEARCH', 'DALLAS', 111, 201 from dual union all
6 select 20, 'RESEARCH', 'CTWN', 111, 202 from dual union all
7 select 30, 'SALES', 'CHICAGO', 111, 301 from dual union all
8 select 40, 'OPERATIONS', 'BOSTON', 112, 401 from dual ),
9 --
10 bi_pd as(
11 select 111 code_id, null pd_type, -1 bi_type from dual union all
12 select 112, -1, null from dual),
13 --
14 t as(
15 select a.deptno,a.sub_deptno from dept_x a, bi_pd b
16 where a.code_id = b.code_id and b.pd_type = -1)
17 --
18 select a.deptno,a.sub_deptno
19 from dept_x a, bi_pd b
20 where a.code_id = b.code_id and b.bi_type = -1 and
21 (a.deptno) not in (select deptno from t)
22 union
23 select deptno,sub_deptno from t;
DEPTNO SUB_DEPTNO
10 103
20 201
20 202
30 301
40 401 -
Restrictive query always returns no rows
I am trying to run a query with a where clause, but I'm always getting no rows returned. I am obviously overlooking something. Here are my scripts that are on the employee dept tables.
The scripts run without any errors and when I do a 'select * from dept_xml' I get the complete XML output. However if I run the query
select * from dept_xml
where existsNode(sys_nc_rowinfo$, '/DEPT_T[DEPTNO=40]') = 1
no rows returned
WHY??
drop type emp_t force
drop type emplist_t force
drop type dept_t force
drop type deptlist_t force
drop type depts_t force
CREATE OR REPLACE TYPE emp_t AS OBJECT
EMPNO NUMBER(4),
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(8,2),
COMM NUMBER(8,2)
CREATE OR REPLACE TYPE emplist_t AS TABLE OF emp_t
CREATE OR REPLACE TYPE dept_t AS OBJECT
DEPTNO NUMBER(2),
DNAME VARCHAR2(14),
LOC VARCHAR2(13),
EMPS EMPLIST_T
CREATE OR REPLACE TYPE deptlist_t AS TABLE OF dept_t
CREATE OR REPLACE TYPE depts_t AS OBJECT
DEPTS DEPTLIST_T
begin
dbms_xmlschema.deleteSchema('http://www.oracle.com/depts.xsd', 4);
dbms_xmlschema.registerSchema('http://www.oracle.com/depts.xsd', dbms_xmlschema.generateschema('SCOTT','DEPT_T'),TRUE,FALSE);
end;
CREATE OR REPLACE VIEW dept_xml OF XMLTYPE
XMLSCHEMA "http://www.oracle.com/depts.xsd" ELEMENT "DEPT_T"
WITH OBJECT ID (sys_nc_rowinfo$.extract('/DEPT_T/DEPTNO').getNumberVal())
AS
SELECT dept_t(d.deptno,
d.dname,
d.loc,
cast(multiset(SELECT emp_t(e.empno,
e.ename,
e.job,
e.mgr,
e.hiredate,
e.sal,
e.comm)
FROM emp e
WHERE e.deptno = d.deptno)
AS emplist_t))
FROM dept d;#1. I would strong recommend using the SQL/XML operators (XMLElement, XMLForest etc)to define your view, rather than creating SQL Types. We will be focusing future development on improving the performance and functionality of the SQL/XML operators, so these operators are now the preferred approach.
#2 Please post the XML document that is generated by teh view. I suspect that the XPATH expression does not match the generated docuemnt. -
Oracle 11g:Query to return only 1 to 1 relationship & random selection
Hi
I have a complex query to modify but I have below the sample tables and data with only very few fields(only affected fields).
Query based on 2 tables b_test and s_test.
Pls see below.
create table b_test(building_id number not null,invalid varchar2(1));
create table s_test(sub_building_id number not null,building_id number ,invalid varchar2(1),sequence_no number);
insert into b_test values (1000,'N');
insert into b_test values(2000,'N');
insert into b_test values(3000,'N');
commit;
insert into s_test values(1,1000,'N',90);
insert into s_test values(2,1000,'N',91);
insert into s_test values(3,1000,'N',92);
insert into s_test values(4,1000,'Y',93);
insert into s_test values(5,NULL,'N',NULL);
insert into s_test values(1,2000,'N',94);
insert into s_test values(2,2000,'N',95);
insert into s_test values(3,2000,'N',96);
insert into s_test values(4,2000,'N',97);
insert into s_test values(5,2000,'N',98);
insert into s_test values(6,NULL,'N',NULL);
insert into s_test values(10,3000,'N',99);
insert into s_test values(11,3000,'N',100);
commit;The query below returns all rows required:(also see results:)
select b.building_id,b.invalid,s.sub_building_id,s.sequence_no from b_test b,
(select * from s_test where invalid='N') s
where b.building_id = s.building_id(+)
and b.invalid='N'
Results:
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
1000 N 2 91
1000 N 3 92
2000 N 1 94
2000 N 2 95
2000 N 3 96
2000 N 4 97
2000 N 5 98
3000 N 10 99
3000 N 11 100Now there are 2 requirements:
1)How can the above query be changed so that 1:1 relationship if sub_building_id is returned?i.e For 1 building_id, only show 1 sub_building(This could be a random selection)
(Pls help with query)
The results would be like
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
2000 N 1 94
3000 N 11 1002)How can the same SEQUENCE_NO be shown for all sub_buildings for the same building? (Pls help with query)
The results will be:
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
1000 N 2 90
1000 N 3 90
2000 N 1 94
2000 N 2 94
2000 N 3 94
2000 N 4 94
2000 N 5 94
3000 N 10 99
3000 N 11 99Many thanks!
Edited by: Krithi on 08-Nov-2012 08:48
Edited by: Krithi on 08-Nov-2012 08:55Krithi wrote:
Hi
I have a complex query to modify but I have below the sample tables and data with only very few fields(only affected fields).
Query based on 2 tables b_test and s_test.
Pls see below.
create table b_test(building_id number not null,invalid varchar2(1));
Thanks for posting the CREATE TABLE and INSERT statements, and your existing query; that's very helpful.
The query below returns all rows required:(also see results:)
select b.building_id,b.invalid,s.sub_building_id,s.sequence_no from b_test b,
(select * from s_test where invalid='N') s
where b.building_id = s.building_id(+)
and b.invalid='N'
Results:
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
1000 N 2 91
1000 N 3 92
2000 N 1 94
2000 N 2 95
2000 N 3 96
2000 N 4 97
2000 N 5 98
3000 N 10 99
3000 N 11 100
When I run your query, I get NULL for sequence_no on the last 2 rows, where building_id=3000. The numbers 99 and 100 don't seem to occur in either table. Did you post the worng sample data and/or results?
>
Now there are 2 requirements:
1)How can the above query be changed so that 1:1 relationship if sub_building_id is returned?i.e For 1 building_id, only show 1 sub_building(This could be a random selection)
(Pls help with query) Here's one way:
WITH got_r_num AS
SELECT sub_building_id
, building_id
, sequence_no
, ROW_NUMBER () OVER ( PARTITION BY building_id
ORDER BY sequence_no
) AS r_num
FROM s_test
WHERE invalid = 'N'
SELECT b.building_id
, b.invalid
, r.sub_building_id
, r.sequence_no
FROM b_test b
LEFT OUTER JOIN got_r_num r ON r.building_id = b.building_id
WHERE NVL ( r.r_num
, 1
) = 1
ORDER BY b.building_id
;This is called a Top-N Query , because we're picking N items (N = 1 in this case) from the top of an ordered list. What makes one item the "top", and another one "lower"? That's determined by the analytic ORDER BY clause, in this case
ORDER BY sequence_noThat means the row with the lowest sequence_no (for each building_id) will get r_num=1. If you want a random row from that building_id to be chosen as #1, then you can change the analytic ORDER BY clause to
ORDER BY dbms_random.valueYou can ORDER BY anything you like, even a constant, but you must have an analytic ORDER BY clause. ROW_NUMBER requires an analytic ORDER BY clause.
The results would be like
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
2000 N 1 94
3000 N 11 100
Again, I don't see where the 100 comes from. The results I get are:
BUILDING_ID I SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
2000 N 1 94
3000 N 11
2)How can the same SEQUENCE_NO be shown for all sub_buildings for the same building? (Pls help with query)
SELECT b.building_id
, b.invalid
, s.sub_building_id
, MIN (s.sequence_no) OVER ( PARTITION BY s.building_id)
AS seq_no
FROM b_test b
LEFT OUTER JOIN s_test s ON s.building_id = b.building_id
AND s.invalid = 'N'
The results will be:
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
1000 N 2 90
1000 N 3 90
2000 N 1 94
2000 N 2 94
2000 N 3 94
2000 N 4 94
2000 N 5 94
3000 N 10 99
3000 N 11 99
Again, I don't see where you get sequence_no = 99. The results I get are:
BUILDING_ID I SUB_BUILDING_ID SEQ_NO
1000 N 1 90
1000 N 2 90
1000 N 3 90
2000 N 1 94
2000 N 2 94
2000 N 5 94
2000 N 3 94
2000 N 4 94
3000 N 10
3000 N 11Edited by: Frank Kulash on Nov 8, 2012 12:12 PM
Added explanation and results
Edited by: Frank Kulash on Nov 8, 2012 12:28 PM
It looks like you cahnged your sample data from
insert into s_test values(10,3000,'N',NULL);
insert into s_test values(11,3000,'N',NULL);to
insert into s_test values(10,3000,'N',99);
insert into s_test values(11,3000,'N',100);The queries I posted are niow getting 99, like you requested. -
All,
I have 2 dimension tables and 1 logical fact table
a01_bi_agency_interest_dim
a01_bi_dsk_central_file_dim
tier2_facts
1 Complex Join in Physical Layer
A01_BI_AGENCY_INTEREST_DIM.MASTER_AI_ID = A01_BI_DSK_CENTRAL_FILE_DIM.MASTER_AI_ID AND A01_BI_AGENCY_INTEREST_DIM.INT_DOC_ID = A01_BI_DSK_CENTRAL_FILE_DIM.INT_DOC_ID
2 Logical Joins in BMM
A01_BI_AGENCY_INTEREST_DIM to tier2_facts (inner, 0 or 1 to many)
A01_BI_DSK_CENTRAL_FILE_DIM to tier2_facts (inner, 0 or 1 to many)
Query only returns 1 row. Should return many rows, I have checked the data through sql queries in SqlPlus.
Query from advanced tab.
SELECT A01_BI_AGENCY_INTEREST_DIM.MASTER_AI_NAME saw_0,
A01_BI_DSK_CENTRAL_FILE_DIM.INT_DOC_ID saw_1
FROM TIER2 ORDER BY saw_0, saw_1
Any help would be appreciated. I am missing something, but doesn't make sense.
Thanks,
KathyIt doesn't do the join and I get 1 record returned with zero's for both values. Why doesn't it pick up my join?
-------------------- SQL Request:
SET VARIABLE QUERY_SRC_CD='Report';SELECT A01_BI_AGENCY_INTEREST_DIM.MASTER_AI_ID saw_0, A01_BI_DSK_CENTRAL_FILE_DIM.INT_DOC_ID saw_1 FROM TIER2 ORDER BY saw_0, saw_1
+++300000:300004:----2012/06/01 12:44:51
-------------------- General Query Info:
Repository: Star, Subject Area: TIER2, Presentation: TIER2
+++300000:300004:----2012/06/01 12:44:51
-------------------- Cache Hit on query:
Matching Query: SET VARIABLE QUERY_SRC_CD='Report';SELECT A01_BI_AGENCY_INTEREST_DIM.MASTER_AI_ID saw_0,
A01_BI_DSK_CENTRAL_FILE_DIM.INT_DOC_ID saw_1
FROM TIER2 ORDER BY saw_0, saw_1
Created by: Administrator
+++300000:300004:----2012/06/01 12:44:51
-------------------- Query Status: Successful Completion
+++300000:300004:----2012/06/01 12:44:51
-------------------- Physical Query Summary Stats: Number of physical queries 1, Cumulative time 0, DB-connect time 0 (seconds)
+++300000:300004:----2012/06/01 12:44:51
-------------------- Rows returned to Client 1
+++300000:300004:----2012/06/01 12:44:51
-------------------- Logical Query Summary Stats: Elapsed time 0, Response time 0, Compilation time 0 (seconds) -
SQL Query returning no rows, please help!!
I have a table that contains user audits for a particular procedures alongwith the date stamp. Now, I want to list all the procedures not accessed by the users within the last 6 months. Or, all the procedures that have not been used/accessed during the last 6 months.
This is what I am trying but is not returning any rows:
SELECT DISTINCT proc_name,
TRUNC (entry_date)
FROM log_web
WHERE proc_name NOT IN (SELECT proc_name
FROM log_web
WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180))
ORDER BY 2 DESC
Please advise.
Thank you in advance.Two possibilities leap to mind.
First, are you sure that there are any prodcedures not accessed in the last six months?
Second, is there a chance that there could be records with a null value in proc_name? If the sub-query used in a NOT IN predicate returns even one null value, the query will return no rows.
Does this return rows?
SELECT DISTINCT proc_name, TRUNC(entry_date)
FROM log_web
WHERE proc_name NOT IN (SELECT proc_name
FROM log_web
WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180) and
proc_name IS NOT NULL)
ORDER BY 2 DESCJohn -
Query returns more row than expected
1. select * from view_name where col1 = 'value1' returns 12 rows
2. select * from (view script) where col1 = 'value1' returns 24 rows
i have a view called view_name. If i use view_name directly in the query, it returns 12 rows. But if i use the select script directly in from clause, it returns more rows. I am not able to find out why it is happening so. Any pointers will be helpful.Are you saying that the SQL for view_name and view_script are identical? Can you post them?
-
Query return no rows in Answers but retrun rows in sql
Hi all,
I have the following query which return 3 rows in SQL promple but return no row in Answer and Execute direct request what is the problem any idea?
select abc_date,abc_asset_desc,sum(abc_market_val_lcy+abc_int_accr_lcy) "Stock"
from abc
group by abc_date,abc_asset_descRegardsHi,
i really appriciate your reply
pls tell me briefly from where i can set log-level > 2 ?? and from where check the physical log of SQL ?
Followig message is arise at server log
ORA-01455 converting column overflow integer datatype at OCI call OCIStmtFetch,Bulk fetched failed
Message was edited by:
53637 -
Return the rows of the table where a column contains a specific value first
I want my query to return the rows of the table where a column contains a specific values first in a certain order, and then return the rest of the rows alphabetized.
For Example:
Country
ALBANIA
ARGENTINA
AUSTRALIA
CANADA
USA
Now i want USA and CANADA on top in that order and then other in alphabetized order.
Edited by: 986155 on Feb 4, 2013 11:12 PM986155 wrote:
If it is 2 then i can write a case... i want generalised one where may be around 5 or 6 mentioned should be in descending order at the top and remaining in ascending order there after.Computers tend not to work in 'generalized' ways... they require specifics.
If you store your "top" countries in a table you can then simply do something like...
SQL> ed
Wrote file afiedt.buf
1 with c as (select 'USA' country from dual union
2 select 'Germany' from dual union
3 select 'India' from dual union
4 select 'Australia' from dual union
5 select 'Japan' from dual union
6 select 'Canada' from dual union
7 select 'United Kingdom' from dual union
8 select 'France' from dual union
9 select 'Spain' from dual union
10 select 'Italy' from dual
11 )
12 ,t as (-- top countries
13 select 'USA' country from dual union
14 select 'United Kingdom' from dual union
15 select 'Canada' from dual
16 )
17 select c.country
18 from c left outer join t on (t.country = c.country)
19* ORDER BY t.country, c.country
SQL> /
COUNTRY
Canada
USA
United Kingdom
Australia
France
Germany
India
Italy
Japan
Spain
10 rows selected. -
below join query is returning any rows
both table have equal job no, job card main table having job date and job quote service have comm_pay
all data is there but i execute below qyery is not returning any rows pls how to resolve.
select
a.job_no,
a.customer_code,
a.client_name2,
b.final_price,
b.comm_value,
b.comm_pay
from
job_card_main a,
job_quote_service b
where
a.job_no=b.job_no
and
a.job_date between :FD and :TD
and
b.comm_pay:CP;Dont think there is any problem with your code as long as you are data is correct and you are passing the correct date values.
WITH job_card_main AS
(SELECT 1 JOB_NO, 2 CUSTOMER_CODE, 3 CLIENT_NAME2, TO_DATE('12-mar-11','dd-mon-yy') JOB_DATE FROM DUAL),
job_quote_service AS
(SELECT 1 JOB_NO, 2 FINAL_PRICE, 3 COMM_VALUE, 'IND' COMM_PAY FROM DUAL)
select
a.job_no,
a.customer_code,
a.client_name2,
b.final_price,
b.comm_value,
b.comm_pay
from
job_card_main a,
job_quote_service b
where
a.job_no=b.job_no
and
a.job_date between TO_DATE('11-mar-11','dd-mon-yy') and TO_DATE('16-mar-11','dd-mon-yy')
and
b.comm_pay = 'IND'
Output:
"JOB_NO" "CUSTOMER_CODE" "CLIENT_NAME2" "FINAL_PRICE" "COMM_VALUE" "COMM_PAY"
"1" "2" "3" "2" "3" "IND"
Maybe you are looking for
-
MaxT3MessageSize in Weblogic 5.1
I'm trying to set the maximum size for a T3 message using weblogic 5.1, but am unable to find any reference to this parameter using wls 5.1. Did this parameter exist back then? I need to send large JMS messages to a wls 5.1 server. Thanks
-
Commenting & Markup Toolbar is missing, gone
Adobe Acrobat 8 Professional Version 524289.2.0 Windows XP I cannot find this toolbar. I right-click on the toolbar and this is not one of the choices. I go to View>Toolbar> and "Commenting & Markup" is not one of the selections. I go to View > Toolb
-
IPhone - Safari parent window focus problem
Hi All, I am having a peculiar problem with a website i am developing. The problem *only* happens on the iPhone(safari). My setup is as follows. 1) I have a CLIENT page - shows an initial page, and has a login button. 2) User clicks on the LOGIN butt
-
Isync doesn't work under mac os 10.4.5
Hi. My isync won't work after my recent update to 10.4.5 -- I just get the swirling colored disk of death when I click on SYNC under SYSTEM PREFERENCES and have to force quit. What's going on? Thanks. Lisa
-
How to merge amr files? puzzling
Hi, I would like to program an application to merge 2 amr files together. According to my knowledge, the header of the AMR file has to be 0x23, 0x21, 0x41, 0x4D, 0x52 and 0x0A. the rest are sets of 1-byte header frame; followed by audio data. So I st