Join v.s. Subquery
I have a user query looks like this:
select LASTNAME,MIDDLENAME,FIRSTNAME,PHONE
from giver
where giver_nbr=
(select giver_nbr
from giver_visit
where giver_id = 1902 and visit_nbr= '0001' )
And I am wondering should this be changed to:
select a.LASTNAME,a.MIDDLENAME,a.FIRSTNAME,a.PHONE
from giver a, giver_visit b
where a.giver_nbr=b.giver_nbr
and b.giver_id = 1902
and b.visit_nbr='0001'
I looked into the explain plan and seemed to me that
the second query had a higher cost. I thought equal
join should be preferred over the subquery???
Can anybody shed some light on this? Thanks a lot!
1)select LASTNAME,MIDDLENAME,FIRSTNAME,PHONE
from giver
where giver_nbr=
(select giver_nbr
from giver_visit
where giver_id = 1902 and visit_nbr= '0001' )
2)select a.LASTNAME,a.MIDDLENAME,a.FIRSTNAME,a.PHONE
from giver a, giver_visit b
where a.giver_nbr=b.giver_nbr
and b.giver_id = 1902
and b.visit_nbr='0001'
In this scenario I would prefer the sub query to join for below reasons
1) You are not retrieving any info from the second table
2) The subquerys returns only one row
3) The join query has the over head of merging or NL operation which the sub query does not have
Similar Messages
-
ORA-01799: a column may not be outer-joined to a subquery
Hi,
How to solve this problem below?
and id2.invoice_line_id*(+)*=(select min(invoice_line_id)
from TW.invoice_detail
where invoice_id=239917
and (bl_amount_currency='USD' AND actual_amount_currency='VND'
OR bl_amount_currency='VND' AND actual_amount_currency='USD')
ERROR at line 150:
ORA-01799: a column may not be outer-joined to a subquery
Since there's an uncertain existence in id2, it needs to be outer-joined to that!
Bst Rgds,
HuaMinYou cant do a outer join on a sub query. Can you describe what are you trying to do?
-
How to Do This In a Join Not A Subquery
I have two tables:
USERS
user_id
fname
lname
USER_SITES
user_id
site_id
confirmed
There is a one to many relationship between USERS and USER_SITES (a user can belong to many sites).
I am looking for a query that will return only users who are a member of site_id=2, not site_id=4. The following subquery does the trick:
select * from USERS where user_id in (select user_id from USER_SITES where site_id=2) and user_id not in (select user_id from USER_SITES where site_id=4);
...but I would like to do this using only JOINS (they are generally faster....and also its kind of frustrating me that I cannot figure out how to do it in a join).Second attempt.
with users as
select 1 as user_id, 'a' as fname, 'b' as lname from dual union all
select 2 as user_id, 'a' as fname, 'b' as lname from dual union all
select 3 as user_id, 'a' as fname, 'b' as lname from dual
user_sites as
select 1 as user_id, 2 as site_id from dual union all
select 2 as user_id, 4 as site_id from dual union all
select 3 as user_id, 2 as site_id from dual union all
select 3 as user_id, 4 as site_id from dual
-- end of test data
select user_id, fname, lname from
select u.user_id,
u.fname,
u.lname,
max(site_id) over (partition by u.user_id) as m
from users u
join user_sites s on u.user_id = s.user_id
where s.site_id in (2,4)
where m = 2;
USER_ID FNAME LNAME
1 a b Edited by: Cyn on Feb 23, 2010 2:46 PM
Edited by: Cyn on Feb 23, 2010 3:02 PM -
Hi
I have a main query as below;
SELECT Forenames, Surname, Mobile, StaffStatus, tblStaff.ID
FROM tblStaff
How can I add the result of below sub query 'Jobs' as a column in the query above where tblStaff.ID = tblStaffBookings.StaffID?
SELECT COUNT(ID) AS Jobs
FROM tblStaffBookings
GROUP BY tblStaffBookings.StaffID
Thanks
RegardsAnother way is this
SELECT Forenames, Surname, Mobile, StaffStatus, ID , Cnt
FROM tblStaff s
CROSS APPLY (SELECT COUNT(ID) AS Cnt
FROM tblStaffBookings
WHERE StaffID = s.ID
)sb
Change CROSS APPLY to OUTER APPLY if you want all records from tblStaff regardless of match in tblStaffBookings (ie to get details of Staff without bookings also)
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How do you join two tables from different Oracle schemas using a subquery
I am trying to join two tables from different Oracle schemas using a subquery. I can extract data from each of the tables without a problem. However, when I combine the select statements using a subquery I get the Oracle error *'ORA-00936: missing expression'*. Since each SELECT statement executes on its own without error I don't understand what is missing. The result set I am trying to get is to match up the LINE_ID from PDTABLE_12_1 in schema DD_12809 with the MAT_DESCRIPTION from table PDTABLE_201 in schema RA_12809.
The query is as follows:
sql = "SELECT [DD_12809].[PDTABLE_12_1].LINE_ID FROM [DD_12809].[PDTABLE_12_1] JOIN " _
+ "(SELECT [RA_12809].[PDTABLE_201].MAT_DESCRIPTION " _
+ "FROM [RA_12809].[PDTABLE_201]) AS FAB " _
+ "ON [DD_12809].[PDTABLE_12_1].PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS"
The format of the query is copied from a SQL programming manual.
I also tried executing the query using a straight JOIN on the two tables but got the same results. Any insight would be helpful. Thanks!
Edited by: user11338343 on Oct 19, 2009 6:55 AMI believe you are receiving the error because you are trying to JOIN on a column that doesn't exist. For example you are trying to join on FAB.PIPING_MATER_CLASS but that column does not exist in the subquery.
If you want to do a straight join without a subquery you could do the following
SELECT DD_12809.PDTABLE_12_1.LINE_ID
, FAB.MAT_DESCRIPTION
FROM DD_12809.PDTABLE_12_1
JOIN RA_12809.PDTABLE_201 AS FAB ON DD_12809.PDTABLE_12_1.PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS HTH! -
Scalar subquery or outer join rule of thumb
Hi,
is there any particular reason for choosing one over other method ?
select t1.col1, (select t.2col2 from t2 where t2.id = t1.id) smth from t1;
--over
select t1.col1, t2.col2 from t1
where
t1.id = t2.id(+)
I think those are logicaly equal .Please advice fro DB 9.2.0.8
Regards.
GregDavid_Aldridge wrote:
I would always use the explicit join method. It's easier to follow, particularly for more complex queries, and I believe that the subquery method is limited in the join mechanisms it will use.Exactly why I hinted he should look at the explain plan, so he can learn the difference for himself.
Explicit join will use appropriate join method, whereas subquery will generally be less performant. There are of course various factors involved, so the explain plan should be examined for the required tables and data, especially the amount of IO being performed. -
Correlated sub-query/outer join problem
Hi,
I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
select b.book_from,
b.book_to,
b.flat_rate,
nvl(c.discount,0),
p.hourly,
p.half_day,
p.daily,
p.discountable,
p.surcharge,
l.evening_start,
nvl(b.full_day,'N')
from booking.bookings b,
booking.customer c,
booking.room_prices p,
booking.rooms r,
booking.location l
where b.id = 9272
and c.id = b.customer
and b.room = p.room
and b.room = r.id
and r.loc = l.id
and p.from_date =
select max(p2.from_date)
from booking.room_prices p2
where p2.room = p.room
and p2.from_date < b.book_from
Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
Thanks,
HazelThanks for both of your responses.
Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
Here are some table creation scripts and test data to insert:
CREATE TABLE BOOKINGS
ID NUMBER NOT NULL,
ROOM NUMBER NOT NULL,
CUSTOMER NUMBER NOT NULL,
BOOK_FROM DATE NOT NULL,
BOOK_TO DATE NOT NULL,
CONFIG VARCHAR2(24) NOT NULL,
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
DELEGATES NUMBER,
NARRATIVE VARCHAR2(256),
CONTACT_DETAILS VARCHAR2(400),
CONFIRMED VARCHAR2(1),
CANC_REASON NUMBER,
FULL_DAY VARCHAR2(1),
FLAT_RATE NUMBER,
STANDBY NUMBER,
TOTAL_STANDBY_TIME DATE,
PRE_STANDBY_TIME DATE,
PRE_STANDBY NUMBER,
GL_CODE VARCHAR2(20)
CREATE TABLE CUSTOMER
ID NUMBER NOT NULL,
CUSTOMER VARCHAR2(160) NOT NULL,
CONTACT_ADDRESS VARCHAR2(240),
CONTACT_TELEPHONE VARCHAR2(20),
CONTACT_EMAIL VARCHAR2(160),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
DISCOUNT NUMBER(5,2),
CUST_TYPE VARCHAR2(1),
CONTACT_FAX VARCHAR2(20),
DEBTOR_NO VARCHAR2(20),
BC_CONTACT VARCHAR2(64)
CREATE TABLE ROOMS
ID NUMBER NOT NULL,
LOC NUMBER NOT NULL,
NAME VARCHAR2(160) NOT NULL,
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
ACTIVE VARCHAR2(1),
ROOM_DESC VARCHAR2(2000)
CREATE TABLE LOCATION
ID NUMBER NOT NULL,
NAME VARCHAR2(240) NOT NULL,
ADDRESS VARCHAR2(240),
PCODE VARCHAR2(8),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
CONF_RDF VARCHAR2(10),
CLOSING VARCHAR2(5),
EVENING_START VARCHAR2(5)
CREATE TABLE ROOM_PRICES
ROOM NUMBER NOT NULL,
FROM_DATE DATE NOT NULL,
HOURLY NUMBER(6,2),
HALF_DAY NUMBER(6,2),
DAILY NUMBER(6,2),
DISCOUNTABLE VARCHAR2(1),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
SURCHARGE NUMBER(6,2)
Insert into bookings
(ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
Values
(9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
Insert into customer
(ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
Values
(4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
Insert into rooms
(ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
Values
(7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
Insert into location
(ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
Values
(308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
Thanks,
Hazel -
Outer join problem (ORA-01799)
We have a database design roughly as follows:
- A STAFF table (columns don't matter here).
- Resources have a cost per hour that varies over time, so we have a STAFF_COST table with an effective date and a cost per hour
- A PROJECT table (columns don't matter here).
- Projects can have staff assigned, so we have a PROJECT_STAFF table which has foreign keys to the PROJECT and STAFF table.
- Project staff have a cost per hour, which can vary over time, and be different to the (default) staff costs. So we have a PROJECT_STAFF_COST table which uses the PROJECT_STAFF foreign key, with an effective date and a cost per hour
- Staff work on tasks so we have a TIMESHEET_TASK and TIMESHEET_DAY tables which define a project worked on, task within the project (optional as time can be 'entered against the project', who is recording the time, the hours worked and the day the hours were worked.
So when timesheet information is entered we have three scenario's that we need to cover.
1) The resource is a member of the project and the hours were worked on a day for which we have a project staff cost. That is, the project staff cost table has one or more rows for the staff member assigned to the given project with an effective date before the date the hours were entered against.
2) The resource is a member of the project but the hours were worked on a day for which we do not have a project staff cost. That is, the project staff cost table has one or more entries for the staff member assigned to the given project, but all the effective dates are after the date the hours were entered against.
3) The resource is not a member of the project. That is, the project staff cost table does not have any rows for the staff member. Time was entered 'against the project'.
We need to work out the actual cost of the project. So we need to retrieve every day's timesheet entry, returning the hours assigned and the cost per hour relevant for that day. I have the following query:
select tsh.staff_id, s.full_name, tsd.entry_date, tsd.hours as ProjectHours,
psCOST_INFO.cost_per_hour as ProjectCost
from timesheet_day tsd
inner join timesheet_task tst on tst.timesheet_task_id = tsd.timesheet_task_id
inner join timesheet_header tsh on tst.timesheet_header_id = tsh.timesheet_header_id
inner join staff s on s.staff_id = tsh.staff_id
left join (Select ps.project_id, ps.staff_id, psc.project_staff_id, psc.effective_date, psc.cost_per_hour
from project_staff ps
inner join project_staff_cost psc on ps.project_staff_id = psc.project_staff_id) as psCOST_INFO
on psCOST_INFO.staff_id = tsh.staff_id and psCOST_INFO.project_id = tst.project_id
and psCOST_INFO.effective_date = (select max(ps2.effective_date) from project_staff_cost ps2
where ps2.project_staff_id = psCOST_INFO.project_staff_id
and ps2.effective_date <= tsd.entry_date)
where tst.project_id = 55825
Using the left join covers scenario's 2 and 3 above because I will get null in the cost columns and can then take appropriate action. If I were to use an inner join, then hours in timesheets from scenario's 2 and 3 would be excluded, which is not what we want.
The subselect using the MAX aggregate function is required to get the cost per hour most relevant for the timesheet day. That is, if there are several effective dates for the project staff member before the date in question, we want the most recent one. We can't just use the MAX one, however in case there is an effective date after the particular timesheet date. Sheesh...
This query works fine in SQL Server. It it not allowed in Oracle and returns an ORA-01799 column may not be outer joined to a subquery.
I'm not going to bother to ask why not. I just need a way to do what I want. I've spent days trying to move the code around but I either end up with an inner join (which returns fewer rows than I want) or it just plain don't work.
Can someone help me rework this query to achieve the result I want?
Thanks, AndrewThanks for your reply, Laurent. In my experience trying to cut important corners in explaining a problem only serves to make it more difficult to solve. That pretty much was the smallest reproducable query that demonstrates the complexity of the problem I have. I'm not just trying to get which publishers live in the 'CA' state here...
From what I have just read about rank() it serves the same purpose as max() on a given column, and getting the maximum or top ranked one just doesn't cut it. As I said in my original post that provided all the relevant (and no spurious) information on the problem, it is possible that there are effective dates AFTER the date we are interested in and they have to be excluded.
I have to get the project staff cost row with the latest date that is before the timesheet date. That means I have to reference data in the outer query. Oracle seems to have a problem with that when used in an outer join.
We are currently going down the track of 3 UNION'd statement to cover the 3 scenario's. A single query would be more efficient so if anyone can provide guidance I would appreciate it.
Thanks, Andrew -
Using Subquery returns more than 1 ROW.Please guide
Hi
I am using inner join to return back a row
Now,when I use the sub query.I get the message:
ORA_01427 : Single row subquery returns more than one row
select t.trade_id from trade t
inner join prod_desc p
on t.product_id = p.product_id
inner join trade_keyword k
on t.trade_id = k.trade_id
where t.trade_status in( 'PENDING_TERM','TERMINATED')
and k.trade_id = (Select trade_id from trade_keyword
where keyword_name like '%FeeConfirmed%'
and keyword_value = 'true')I was wondering if I need to use a join in the subquery
like
= (Select trade_id from trade_keyword
where keyword_name like '%FeeConfirmed%'
and keyword_value = 'true'
and trade_id = t.trade_id)Or is there a better way?
Please adviseYou need to use the "IN" operator instead of the equals sign "=".
as in
and k.trade_id in (your subselect)However I just noticed, that maybe you don't need a subselect at all. You already joined the keyword table. There is no reason to select from it a second time. Of course this depends on your data and what do you want to select.
select t.trade_id from trade t
inner join prod_desc p on t.product_id = p.product_id
inner join trade_keyword k on t.trade_id = k.trade_id
where t.trade_status in( 'PENDING_TERM','TERMINATED')
and k.keyword_name like '%FeeConfirmed%'
and k.keyword_value = 'true';Edited by: Sven W. on Sep 1, 2008 5:36 PM -
Can anyone tell me WHY Oracle won't allow sub-queries in outer joins?
Hi,
I've recently been tasked with converting a series of InterBase dbs to Oracle.
Many of the queries in the InterBase dbs use sub-queries in outer joins. Oracle won't countenance this (01799 - a column may not be outer-joined to a subquery).
I can get around it using functions but WHY won't Oracle allow this?
SQL Server allows it, InterBase allows it (I don't know about ANSI SQL) but it seems to be a common enough technique...
I'm just curious (and also a little frustrated!).
Thanks in advance,,,Hi,
>>Oracle treat an empty string as a NULL
Well, you same answer your question. Because it is empty
SGMS@ORACLE10> create table tab (cod number, name varchar2(1));
Table created.
SGMS@ORACLE10> insert into tab values (1,'');
1 row created.
SGMS@ORACLE10> insert into tab values (2,' ');
1 row created.
SGMS@ORACLE10> commit;
SGMS@ORACLE10> select cod,dump(name) from tab;
COD DUMP(NAME)
1 NULL
2 Typ=1 Len=1: 32
SGMS@ORACLE10> select * from tab where name is null;
COD NAME
1Cheers
If you talking about language tools, for example PHP treat empty string <> of NULL values. e.g: functions like is_empty() and is_null()
Message was edited by:
Legatti -
No join in the query involving 2 tables
Friends,
I saw a strange plan for one query in TESTING DB today. Although 2 tables are involved i dont see any join , NL/HJ/SMJ !!
Can you please tell why this might be happening?
Note: i am not facing any performance issue but curious to know what type of optimization oracle is doing here.
It would be great if you could direct me the relevant link in the documentation.
Query text and plan :
SELECT FIRST_NAME
FROM CAMPA.TABLE_A
WHERE NAME_ID =
(SELECT NAME_ID
FROM CAMPA.TABLE_B
WHERE ban=:b1);
Plan hash value: 311916800
| Id | Operation | Name | Rows | Bytes | Cost | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 12 | 2 | | |
| 1 | PARTITION RANGE SINGLE | | 1 | 12 | 1 | KEY | KEY |
| 2 | TABLE ACCESS BY LOCAL INDEX ROWID | TABLE_A | 1 | 12 | 1 | KEY | KEY |
|* 3 | INDEX UNIQUE SCAN | TABLE_A_PK | 1 | | 1 | KEY | KEY |
| 4 | PARTITION RANGE SINGLE | | 2 | 30 | 1 | KEY | KEY |
| 5 | TABLE ACCESS BY LOCAL INDEX ROWID| TABLE_B | 2 | 30 | 1 | KEY | KEY |
|* 6 | INDEX RANGE SCAN | TABLE_B_2IX | 2 | | 1 | KEY | KEY |
Predicate Information (identified by operation id):
3 - access("NAME_ID"= (SELECT "NAME_ID" FROM "CAMPA"."TABLE_B" "TABLE_B"
WHERE "BAN"=TO_NUMBER(:B1)))
6 - access("BAN"=TO_NUMBER(:B1))
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for HPUX: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionWith equality condition can i get NL/HJ join where the outer row source comes from the subquery?
What condition/pre-requisite of NL/HJ join is not met in this case?Don't use an equality condition with a subquery - this implicitly makes available to the CBO an optimisation strategy that can only be used if the subquery is guaranteed to return a single row.
So either use IN rather than = or use a JOIN not a SUBQUERY.
It's a bit of a strange question.
How do I remove this optimisation?
Take away the features that make that optimisation a possibility.
Edited by: Dom Brooks on May 13, 2013 2:20 PM -
hi,
I wanted 2 do some thing like this..
Select A.C1, A.C2
From A
LEFT JOIN B
ON A.C1 = B.C1 AND B.C2 = (SELECT T.C1 FROM T WHERE B.C2 = T.C1);How can i do dis?
It is giving me exception :: ORA-01799: a column may not be outer-joined to a subquery
but
Select A.C1, A.C2
From A
LEFT JOIN B
ON A.C1 = B.C1 AND B.C2 = 5;is working fineHi,
Atishay wrote:
hi,
I wanted 2 do some thing like this..
Select A.C1, A.C2
From A
LEFT JOIN B
ON A.C1 = B.C1 AND B.C2 = (SELECT T.C1 FROM T WHERE B.C2 = T.C1);
Use curly brackets on the \ tags before anbd after formatted text on this site.
How can i do dis?
It is giving me exception :: ORA-01799: a column may not be outer-joined to a subquery
but
Select A.C1, A.C2
From A
LEFT JOIN B
ON A.C1 = B.C1 AND B.C2 = 5;is working fineHere's one way:Select A.C1, A.C2
From A
LEFT JOIN B
ON A.C1 = B.C1
AND B.C2 IN (
SELECT C1
FROM T
Another way is to join b and t before outer-joining to a.
I hope this answers your question.
If not, post a little sample data CREATE TABLE and INSERT statements for all tables) and the results you want from that data. -
Self Join and Aggregate Functions
Hi all,
I am trying a query in TOAD where I need to use an aggregate function MAX and a self join using a subquery. Its working fine when there is no aggregate function but when I tried to use the MAX function then its running for infi time. Is it because of the invalid joins? or because of the usage of the self join and aggregate func?
The query contains some other tables too....
Any one please help....
Thanks in advance,
GToad will bring back a limited set of rows and present them to you giving the impression that the work is done. Adding an aggregate function requires the entire resultset to be traversed.
Yes, post the 2 queries to verify what I am saying. -
Performance difference between left outer join / inner join
Hi,
I've got a complex query which among other things accesses quite a large table. If I use inner join to join this table, the response is quite fast and execution plan shows it uses nested loops to gather the data.
If I change inner join to left outer join, I get a big performance drop. Cost of query goes from 1441 to 28544.
I don't uderstand why there's such a difference. For inner join, database has to remove all the rows that don't have match in inner-joined table. For left join it can keep all records and just return NULL values for records that don't have a match. In my mind left join should be faster, as it seems simpler. And the access plan could be the same, couldn't it?
Execution plan for inner join:
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 288 | 1441 (1)| 00:00:18 |
| 1 | HASH GROUP BY | | 1 | 288 | 1441 (1)| 00:00:18 |
| 2 | NESTED LOOPS OUTER | | 1 | 288 | 1440 (1)| 00:00:18 |
| 3 | NESTED LOOPS | | 1 | 261 | 1438 (1)| 00:00:18 |
| 4 | NESTED LOOPS | | 318 | 74412 | 508 (1)| 00:00:07 |
| 5 | NESTED LOOPS | | 318 | 51834 | 189 (0)| 00:00:03 |
| 6 | TABLE ACCESS BY INDEX ROWID| RESURCE | 1 | 106 | 1 (0)| 00:00:01 |
|* 7 | INDEX UNIQUE SCAN | RESURCE_PRINCIPAL_NAME_INDEX | 1 | | 0 (0)| 00:00:01 |
| 8 | TABLE ACCESS BY INDEX ROWID| TASK_USES_RESURCE | 318 | 18126 | 188 (0)| 00:00:03 |
|* 9 | INDEX RANGE SCAN | TASK_USES_RESUR_IDX$$_0CDC0002 | 318 | | 3 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID | TASK | 1 | 71 | 1 (0)| 00:00:01 |
|* 11 | INDEX UNIQUE SCAN | TASK_PK | 1 | | 0 (0)| 00:00:01 |
| 12 | TABLE ACCESS BY INDEX ROWID | TASK_WORK_HISTORY | 1 | 27 | 3 (0)| 00:00:01 |
|* 13 | INDEX RANGE SCAN | TASK_WORK_HISTORY_INDEX1 | 1 | | 2 (0)| 00:00:01 |
| 14 | TABLE ACCESS BY INDEX ROWID | TASK_USES_RESURCE | 1 | 27 | 2 (0)| 00:00:01 |
|* 15 | INDEX UNIQUE SCAN | TASK_USES_RESURCE_UK1 | 1 | | 1 (0)| 00:00:01 |
For left outer join:
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 318 | 1596K| | 28544 (2)| 00:05:43 |
|* 1 | HASH JOIN OUTER | | 318 | 1596K| 1584K| 28544 (2)| 00:05:43 |
| 2 | VIEW | | 318 | 1580K| | 508 (1)| 00:00:07 |
| 3 | NESTED LOOPS | | 318 | 74412 | | 508 (1)| 00:00:07 |
| 4 | NESTED LOOPS | | 318 | 51834 | | 189 (0)| 00:00:03 |
| 5 | TABLE ACCESS BY INDEX ROWID| RESURCE | 1 | 106 | | 1 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | RESURCE_PRINCIPAL_NAME_INDEX | 1 | | | 0 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID| TASK_USES_RESURCE | 318 | 18126 | | 188 (0)| 00:00:03 |
|* 8 | INDEX RANGE SCAN | TASK_USES_RESUR_IDX$$_0CDC0002 | 318 | | | 3 (0)| 00:00:01 |
| 9 | TABLE ACCESS BY INDEX ROWID | TASK | 1 | 71 | | 1 (0)| 00:00:01 |
|* 10 | INDEX UNIQUE SCAN | TASK_PK | 1 | | | 0 (0)| 00:00:01 |
| 11 | VIEW | | 1480K| 73M| | 23431 (2)| 00:04:42 |
|* 12 | HASH JOIN RIGHT OUTER | | 1480K| 76M| 38M| 23431 (2)| 00:04:42 |
| 13 | TABLE ACCESS FULL | TASK_USES_RESURCE | 1486K| 21M| | 2938 (2)| 00:00:36 |
| 14 | VIEW | | 1445K| 53M| | 15031 (2)| 00:03:01 |
| 15 | HASH GROUP BY | | 1445K| 37M| 110M| 15031 (2)| 00:03:01 |
| 16 | TABLE ACCESS FULL | TASK_WORK_HISTORY | 1445K| 37M| | 3897 (2)| 00:00:47 |
--------------------------------------------------------------------------------------------------------------------------...continued
Complete execution plan for left join:
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 318 | 1594K| | 28544 (2)| 00:05:43 |
|* 1 | HASH JOIN OUTER | | 318 | 1594K| 1584K| 28544 (2)| 00:05:43 |
| 2 | VIEW | | 318 | 1578K| | 508 (1)| 00:00:07 |
| 3 | NESTED LOOPS | | 318 | 74412 | | 508 (1)| 00:00:07 |
| 4 | NESTED LOOPS | | 318 | 51834 | | 189 (0)| 00:00:03 |
| 5 | TABLE ACCESS BY INDEX ROWID| RESURCE | 1 | 106 | | 1 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | RESURCE_PRINCIPAL_NAME_INDEX | 1 | | | 0 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID| TASK_USES_RESURCE | 318 | 18126 | | 188 (0)| 00:00:03 |
|* 8 | INDEX RANGE SCAN | TASK_USES_RESUR_IDX$$_0CDC0002 | 318 | | | 3 (0)| 00:00:01 |
| 9 | TABLE ACCESS BY INDEX ROWID | TASK | 1 | 71 | | 1 (0)| 00:00:01 |
|* 10 | INDEX UNIQUE SCAN | TASK_PK | 1 | | | 0 (0)| 00:00:01 |
| 11 | VIEW | | 1480K| 73M| | 23431 (2)| 00:04:42 |
|* 12 | HASH JOIN RIGHT OUTER | | 1480K| 76M| 38M| 23431 (2)| 00:04:42 |
| 13 | TABLE ACCESS FULL | TASK_USES_RESURCE | 1486K| 21M| | 2938 (2)| 00:00:36 |
| 14 | VIEW | | 1445K| 53M| | 15031 (2)| 00:03:01 |
| 15 | HASH GROUP BY | | 1445K| 37M| 110M| 15031 (2)| 00:03:01 |
| 16 | TABLE ACCESS FULL | TASK_WORK_HISTORY | 1445K| 37M| | 3897 (2)| 00:00:47 |
Query Block Name / Object Alias (identified by operation id):
1 - SEL$1AFB0324
2 - SEL$58A6D7F6 / from$_subquery$_005@SEL$8
3 - SEL$58A6D7F6
5 - SEL$58A6D7F6 / RESURCEWORKER@SEL$2
6 - SEL$58A6D7F6 / RESURCEWORKER@SEL$2
7 - SEL$58A6D7F6 / TASKUSESRESURCE@SEL$1
8 - SEL$58A6D7F6 / TASKUSESRESURCE@SEL$1
9 - SEL$58A6D7F6 / TASK@SEL$1
10 - SEL$58A6D7F6 / TASK@SEL$1
11 - SEL$7EBCC247 / TRW@SEL$3
12 - SEL$7EBCC247
13 - SEL$7EBCC247 / TUR@SEL$4
14 - SEL$6 / TRW_IN@SEL$5
15 - SEL$6
16 - SEL$6 / TWH@SEL$6
Predicate Information (identified by operation id):
1 - access("TRW"."RESURCE_ID"(+)="TASKUSESRESURCE"."RESURCE_ID" AND "TRW"."TASK_ID"(+)="TASK"."ID")
6 - access("RESURCEWORKER"."USER_PRINCIPAL_NAME"=U'jernej')
8 - access("TASKUSESRESURCE"."RESURCE_ID"="RESURCEWORKER"."ID")
10 - access("TASKUSESRESURCE"."TASK_ID"="TASK"."ID")
12 - access("TUR"."RESURCE_ID"(+)="TRW_IN"."RESURCE_ID" AND "TUR"."TASK_ID"(+)="TRW_IN"."TASK_ID") Jonathan, I've been to one of your workshops in Ljubljana. I'm still trying to understand everything you explained and use it, but there's much I have to learn and understand.
The way I see this query it should fist join and filter the first three tables and only then join the trw subquery. The problem with this subqrey is task_work_history table, which is accessed in very different ways in different places, so there will always be many reads to gather required data. For now, however, I'd be hapy to just bring the performance of inner join to left join... -
Limitation of the number of values in an LOV
Greetings,
I have a tabular form with few of the columns as LOVs. One of the LOVs returns close to 1000 records and the form is giving me a "PL/SQL Numeric Value error". If I do a rownum < 450 in the LOV query the form works. But I need all the values in the LOV.
Any ideas ow to fix this issue. Your help will be greatly appreciated.
Thanks
Vatsasr**** wrote:
I have a tabular form with few of the columns as LOVs. One of the LOVs returns close to 1000 records and the form is giving me a "PL/SQL Numeric Value error". If I do a rownum < 450 in the LOV query the form works. But I need all the values in the LOV.
Any ideas ow to fix this issue. Your help will be greatly appreciated.The total size of the HTML generated for an LOV-based item in APEX is restricted to 32K—something that can be discovered by a basic search of the forum.
You have not provided enough information to enable anyone to "fix this issue" directly. ALWAYS provide the following information in a question:
<li>Full APEX version
<li>Full DB version and edition
<li>Web server architecture (EPG, OHS or APEX listener)
<li>Browser(s)/version(s) used
<li>Theme
<li>Template(s)
<li>Region type(s)
When discussing a tabular form, always indicate whether it was created using a wizard with generated column items, validations and MRU processing, or created manually using <tt>apex_item</tt> API items and custom validations and processing (or some other combination of these possibilities).
LOVs can be used in rendering a number of APEX items: text look-ups, select lists, radio groups and pop-ups. You have not specified which item type(s) are involved. All of these item types except pop-ups are subject to the 32K restriction.
For text look-ups rendered as Display as Text (based on LOV, does not save state), change the display type to Display as Text (escape special characters, does not save state) and do the the look-up in the query using a join or scalar subquery.
As pointed out above, even if it was possible to render a select list or radio group with 1000 options in APEX, this is way too many for an effective UI. There's also the effect on the overall size of a page: if the tabular form displays 10 rows, and each select list contains 32K of options, how big is the page? How long does it take to download? The maximum number of options I'd use in a select list is the ~200 used in lists of countries. (For select lists used in tabular forms I'd prefer to limit it to about 6!) The workaround for select lists/radio groups is to change them to Popup Key LOVs. -
Hi,
I need help with the following query. I want the balance (bal) with the latest exchange rate available.
Sample table & data
with
FX_RATE as
select 11 as id_date, 1 as id_curr, 47 as EXCH_rate from dual union
select 12, 1, 48 from dual union
select 13, 2, 54 from dual union
select 14, 2, 55 from dual union
select 15, 3, 56 from dual union
select 15, 2, 49 from dual),
TBL_NM as
select 13 as p_date, 2 as p_curr, 200 as bal from dual union
select 14, 2, 200 from dual union
select 15, 2, 200 from dual union
select 16, 2, 200 from dual union
select 17, 2, 200 from dual union
select 11, 5, 100 from dual
select p_date, p_curr, bal * nvl(exch_rate,1) from TBL_NM T LEFT OUTER JOIN FX_RATE F1 on (id_curr = p_curr and F1.id_date = T.p_Date)In the above query for p_date 16 & 17 and p_curr 2 it returns just balance multiplied by exchange rate 1"default". But i want the balance to have data as per latest exchange rate which is of exchange rate 15.
I tried this but returns error ORA-01799: a column may not be outer joined to a subquery ..
with
FX_RATE as
select 11 as id_date, 1 as id_curr, 47 as EXCH_rate from dual union
select 12, 1, 48 from dual union
select 13, 2, 54 from dual union
select 14, 2, 55 from dual union
select 15, 3, 56 from dual union
select 15, 2, 49 from dual),
TBL_NM as
select 13 as p_date, 2 as p_curr, 200 as bal from dual union
select 14, 2, 200 from dual union
select 15, 2, 200 from dual union
select 16, 2, 200 from dual union
select 17, 2, 200 from dual union
select 11, 5, 100 from dual
select p_date, p_curr, bal * nvl(exch_rate,1) from TBL_NM T LEFT OUTER JOIN FX_RATE F1
on (id_curr = p_curr and F1.id_date = (select max(F2.id_date) from FX_RATE F2 where F2.id_curr = T.p_curr and F2.id_Date <= T.p_date))Please advice on how i can achieve this ..The entire query wud be like this .. I've to incorporate in here
CREATE MATERIALIZED VIEW MV_DUMMY
BUILD IMMEDIATE
REFRESH FORCE ON DEMAND
AS
SELECT T.ID_TSACTION_RELEASED
BAL.ID_CONTRACT_BALANCE AS ID_CONTRACT_BALANCE,
T.N_REFERENCE_NUMBER
T.INSTRUMENT_N_REFERENCE
T.ITEM_NUMBER
T.EXTERNAL_SYSTEM_ID
T.SEQUENCE_NUMBER
T.ID_RELEASED_DATE
ROUND(BAL.LC_AVAILABLE_BALANCE * NVL(FX1.EXCHANGE_RATE,1) / NVL(FX2.EXCHANGE_RATE,1) , 4)
BAL.LIABILITY_BALANCE
BAL.LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)
BAL.LIABILITY_CHANGE_USD
BAL.MEMO_LIABILITY_BALANCE
BAL.MEMO_LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)
BAL.MEMO_LIABILITY_CHANGE_USD
BAL.ORIGINAL_FACE_AMOUNT
decode(T.TENOR_CODE,'Time','T','Sight','S','Split Sight Time','SST','Split Multiple Time','SMT',T.TENOR_CODE)
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN T.ID_LIABILITY_CIF
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN T.Id_Beneficiary
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN T.ID_Applicant
END PRIMARY_CUSTOMER_ID,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN plbcif.EXTERNAL_SYSTEM_ID
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN PBCIF.EXTERNAL_SYSTEM_ID
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN pappcif.EXTERNAL_SYSTEM_ID
END PRIMARY_CUSTOMER_EXT_SYS_ID,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN plbcif.CIF_NAME
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN PBCIF.CIF_NAME
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN pappcif.CIF_NAME
END PRIMARY_CUSTOMER_NAME,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN plbbac.BAC
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN pbbac.BAC
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN pappbac.BAC
END PRIMARY_CUST_BAC_CODE,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN nvl(plbmg.MARKET,'NOT APPLICABLE')
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN nvl(pbmg.MARKET,'NOT APPLICABLE')
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN nvl(pappmg.MARKET,'NOT APPLICABLE')
END PRIMARY_CUST_MARKET,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN nvl(plbmg.SUB_MARKET,'NOT APPLICABLE')
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN nvl(pbmg.SUB_MARKET,'NOT APPLICABLE')
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN nvl(pappmg.SUB_MARKET,'NOT APPLICABLE')
END PRIMARY_CUST_SUB_MARKET
FROM F_TSACTION_RELEASED T
LEFT OUTER JOIN D_BAC_CODE BAC
ON (T.BAC_CODE_LIABILITY = BAC.BAC_CODE)
LEFT OUTER JOIN REF_BAC_SORT_CODE REF_BAC
ON (T.BAC_CODE_LIABILITY = REF_BAC.BAC)
LEFT OUTER JOIN F_CONTRACT_BALANCE BAL
ON (T.ID_TSACTION_RELEASED = BAL.ID_TSACTION_RELEASED)
LEFT OUTER JOIN D_MARKET_SEGMENT MG
ON (T.ID_MARKET_SEGMENT = MG.ID_MARKET_SEGMENT)
LEFT OUTER JOIN D_DATE DT
ON (DT.ID_DATE = T.ID_RELEASED_DATE)
LEFT OUTER JOIN D_DATE DB
ON (DB.ID_DATE = BAL.ID_RELEASED_DATE)
LEFT OUTER JOIN D_PROCESSING_UNIT PU
ON (PU.ID_PROCESSING_UNIT = T.ID_PROCESSING_UNIT)
LEFT OUTER JOIN D_BIR_PRODUCT BIRPROD
ON (BIRPROD.ID_BIR_PRODUCT=T.ID_BIR_PRODUCT)
LEFT OUTER JOIN D_GTS_PRODUCT_TYPE GTSPROD
ON (GTSPROD.ID_GTS_PRODUCT_TYPE= T.ID_GTS_PRODUCT_TYPE)
LEFT OUTER JOIN D_GTS_TSACTION_TYPE GTST
ON (GTST.ID_GTS_TSACTION_TYPE = T.ID_GTS_TSACTION_TYPE)
LEFT OUTER JOIN D_CURRENCY CCYT
ON (CCYT.ID_CURRENCY = T.ID_TSACTION_CURRENCY)
LEFT OUTER JOIN d_cif lcif
ON (lcif.id_cif = T.id_liability_cif)
LEFT OUTER JOIN d_cif lbcif
ON (lbcif.id_cif = bal.id_liability_cif)
LEFT OUTER JOIN d_cif bcif
ON (bcif.id_cif = T.id_BENEFICIARY)
LEFT OUTER JOIN d_cif icif
ON (icif.id_cif = T.id_ISSUING_BANK)
LEFT OUTER JOIN d_cif acif
ON (acif.id_cif = T.id_ADVISING_BANK)
LEFT OUTER JOIN d_cif appcif
ON (appcif.id_cif = T.id_applicant)
LEFT OUTER JOIN d_state astate
ON (astate.id_state = acif.id_state)
LEFT OUTER JOIN d_state bstate
ON (bstate.id_state = bcif.id_state)
LEFT OUTER JOIN d_state lstate
ON (lstate.id_state = lcif.id_state)
LEFT OUTER JOIN d_state lbstate
ON (lbstate.id_state = lbcif.id_state)
LEFT OUTER JOIN d_state istate
ON (istate.id_state = icif.id_state)
LEFT OUTER JOIN d_state appstate
ON (appstate.id_state = appcif.id_state)
LEFT OUTER JOIN D_TSACTION_SOURCE TSrc
ON (T.ID_TSACTION_SOURCE = TSrc.ID_TSACTION_SOURCE)
LEFT OUTER JOIN D_COUNTRY LCTRY
ON (LCTRY.ID_COUNTRY = lcif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY LBCTRY
ON (LBCTRY.ID_COUNTRY = lbcif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY BCTRY
ON (BCTRY.ID_COUNTRY = bcif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY ICTRY
ON (ICTRY.ID_COUNTRY = icif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY ACTRY
ON (ACTRY.ID_COUNTRY = acif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY APPCTRY
ON (APPCTRY.ID_COUNTRY = appcif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY PCTRY
ON (PCTRY.ID_COUNTRY = T.ID_PRESENTER_COUNTRY)
LEFT OUTER JOIN D_LOCATION LOC
ON (LOC.ID_LOCATION = T.ID_PROCESSING_LOCATION)
LEFT OUTER JOIN D_CURRENCY BCCYT
ON (BCCYT.ID_CURRENCY = BAL.ID_LIABILITY_CURRENCY)
LEFT OUTER JOIN D_CURRENCY BALCYT
ON (BALCYT.ID_CURRENCY = BAL.ID_BALANCE_CURRENCY)
LEFT OUTER JOIN d_liability_type li
ON (li.id_liability_type = BAL.id_liability_type)
LEFT OUTER JOIN d_cif plbcif
ON (plbcif.id_cif = T.id_liability_cif)
LEFT OUTER JOIN REF_BAC_SORT_CODE plbbac
ON (plbcif.bac_code=plbbac.bac)
LEFT OUTER JOIN D_MARKET_SEGMENT plbmg
ON (plbbac.SORT_CODE=plbmg.MARKET_SEGMENT)
LEFT OUTER JOIN d_cif pbcif
ON (pbcif.id_cif = T.id_BENEFICIARY)
LEFT OUTER JOIN REF_BAC_SORT_CODE pbbac
ON (pbcif.bac_code=pbbac.bac)
LEFT OUTER JOIN D_MARKET_SEGMENT pbmg
ON (pbbac.SORT_CODE=pbmg.MARKET_SEGMENT)
LEFT OUTER JOIN d_cif pappcif
ON (pappcif.id_cif = T.id_applicant)
LEFT OUTER JOIN REF_BAC_SORT_CODE pappbac
ON (pappcif.bac_code=pappbac.bac)
LEFT OUTER JOIN D_MARKET_SEGMENT pappmg
ON (pappbac.SORT_CODE=pappmg.MARKET_SEGMENT)
LEFT OUTER JOIN D_CURRENCY LOCALCYT
ON (LOCALCYT.alpha_code = PU.local_ccy)
LEFT OUTER JOIN D_BRANCH Branch
ON (T.ID_BRANCH = Branch.ID_BRANCH )
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX1
ON (BAL.ID_BALANCE_CURRENCY = FX1.ID_CURRENCY and FX1.ID_DATE = (select max(FX11.ID_DATE) from F_USD_FX_RATE_HISTORY FX11 where BAL.ID_BALANCE_CURRENCY = FX11.ID_CURRENCY and FX11.ID_DATE <= BAL.id_released_date))
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX2
ON (LOCALCYT.ID_CURRENCY = FX2.ID_CURRENCY and FX2.ID_DATE = (select max(FX22.ID_DATE) from F_USD_FX_RATE_HISTORY FX22 where LOCALCYT.ID_CURRENCY = FX22.ID_CURRENCY and FX22.ID_DATE <= BAL.id_released_date))
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX3
ON (BAL.ID_LIABILITY_CURRENCY = FX3.ID_CURRENCY and FX3.ID_DATE = (select max(FX33.ID_DATE) from F_USD_FX_RATE_HISTORY FX33 where BAL.ID_LIABILITY_CURRENCY = FX33.ID_CURRENCY and FX33.ID_DATE <= BAL.id_released_date))Note the lines
ROUND(BAL.MN_AVAILABLE_BALANCE * NVL(FX1.EXCHANGE_RATE,1) / NVL(FX2.EXCHANGE_RATE,1) , 4)
BAL.LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)
BAL.MEMO_LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)
And
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX1
ON (BAL.ID_BALANCE_CURRENCY = FX1.ID_CURRENCY and FX1.ID_DATE = (select max(FX11.ID_DATE) from F_USD_FX_RATE_HISTORY FX11 where BAL.ID_BALANCE_CURRENCY = FX11.ID_CURRENCY and FX11.ID_DATE <= BAL.id_released_date))
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX2
ON (LOCAMNYT.ID_CURRENCY = FX2.ID_CURRENCY and FX2.ID_DATE = (select max(FX22.ID_DATE) from F_USD_FX_RATE_HISTORY FX22 where LOCAMNYT.ID_CURRENCY = FX22.ID_CURRENCY and FX22.ID_DATE <= BAL.id_released_date))
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX3
ON (BAL.ID_LIABILITY_CURRENCY = FX3.ID_CURRENCY and FX3.ID_DATE = (select max(FX33.ID_DATE) from F_USD_FX_RATE_HISTORY FX33 where BAL.ID_LIABILITY_CURRENCY = FX33.ID_CURRENCY and FX33.ID_DATE <= BAL.id_released_date))Thsi is where I need to incorporate the change
Maybe you are looking for
-
How to copy data in a table to another table with different structure
Hi, I am having a table Employee with fields EID, ENAME and Age i want to insert the values into another table Employee1 with fields EID,ENAME,AGE and address. (Address can be null) Can anyone provide the sql query to do this.
-
How do I cancel a download that won't go through....it's waiting
I am trying download music.....there is a problem with my credit card so it won't download...it is in a holding pattern trying to download. My laptop downloaded the music and used the same credit card. My iPad just won't give up. How do I cancel..
-
Toshiba 32c120u only running at 60 Hertz on laptop
I am using a Lenovo T430 and have hooked my laptop up to my Toshiba 32c120u HD LCD TV via a VGA cable. When I look at the display settings, the highest resolution is 1360x768 and the refresh rate is 60 Hertz. When I look in the advanced settings it
-
Ringer volume not in sync with messaging or other alert volume - Verizon Centro
Hello and I apologize in advance if this is in the wrong forum or has been discussed before. I have the Verizon Centro and have found that when I adjust the ringer volume using the side keys, the text message and any other alert volume stays at whate
-
Batch Rename Issues - CS5 - Win7
Bridge (4.0.2.1) will not Batch Rename in sequential order. Have tried several times on different folders and get the same results each time. For example: Folder with 280 images. I request a Batch Rename in Same Folder, numbered sequentially starti