outer join: difference between two queries
Below two queries which should give the same results in my opinion. I want that all records of u_protocol and the pval.u_protocol_variable_value value if necessary.Why the outer join in query2 does not work as in query1?
Query1:
select p.u_protocol_id, i.u_protocol_variable_value
from lims_sys.u_protocol p,
(
select pval.u_protocol_id, pval.u_protocol_variable_value
from lims_sys.u_protocol_variable pvar, lims_sys.u_protocol_value_user pval
where pvar.u_protocol_variable_id = pval.u_protocol_variable_id
and pvar.name = 'VALUE_Protocol_Group'
) i
where p.u_protocol_id = i.u_protocol_id (+)
Query2:
select prt.u_protocol_id, pval.u_protocol_variable_value
from lims_sys.u_protocol prt, lims_sys.u_protocol_variable pvar, lims_sys.u_protocol_value_user pval
where pvar.u_protocol_variable_id = pval.u_protocol_variable_id
and prt.u_protocol_id = pval.u_protocol_id (+)
and pvar.name = 'VALUE_Protocol_Group'
Hello
When you perform an outer join, all conditions on the tables in option must be outer join conditions. Otherwise, the effect is an inner join.
There is one exception: cascade of outer joins, external-junction b of a and c is outside attached to b. In this case, in the b - c join only columns of c are marked with the sign +.
Re - write to obtain the same results as query1, query2 like this:
select prt.u_protocol_id
, pval.u_protocol_variable_value
from lims_sys.u_protocol prt
, lims_sys.u_protocol_variable pvar
, lims_sys.u_protocol_value_user pval
where pvar.u_protocol_variable_id (+) = pval.u_protocol_variable_id -- cascading outer join
and prt.u_protocol_id = pval.u_protocol_id (+)
and pvar.name (+) = 'VALUE_Protocol_Group' -- (+) added
;
I find the syntax ANSI easier to use for all the joins and much easier for outer joins.
Tags: Database
Similar Questions
-
I am building a working method in LiveCycle, and I want to track how long the procedure takes. To do this, I have two time fields, and then a third time field to find the difference between two time fields. Looking at other posts to discussion, I could find a Javascript code that was part of what I wanted, but I can't get the third time field to display in the format I want. I tried to change the habits of the fields and that did not work. Could someone offer some advice on how to change the format or help me with the code? I couldn't figure to attach the actual file, but I have attached a picture of the PDF file and the Javascript code I used. If you look at the TimeIn (hh: mm) and time (hh: mm) areas (on the photo, I have attached), you will notice that the TotalTime comes out like HMM, and I want that it out as hh: mm.
Any help would be greatly appreciated!
Thank you
this.rawValue = (totalHrs > 9? String (totalHrs): '0' + String (totalHrs)) + ':' + (totalMins > 9? String (totalMins): '0' + String (totalMins));
-
Difference between two data aquistion
Hello
I got a data aquistion system that is supposed to keep data acquisition selection until the difference between two points a lot. For example, I get voltage (mv) as 2.31, 2.32, 2.34. 2.33 2.32, 2.33 2.32. the data up to a point, say 0.1V higher or lower than the first. Thewhole procss stop. Thank you for your suggestions.
Try this... (Labview 8.2)
-
using outer joins if the two column is null? Use only (+)
Hi all
create the table xxc_tr_num (tl_number number, tr_no number tl_no_id);
insert into xxc_tr_num values (123,100,222);
insert into xxc_tr_num values (124,100,333);
create the table xxc_od_tab (tl_number number, tl_id number);
insert into xxc_od_tab values (123,001);
insert into xxc_od_tab values (null, null);
create table xxc_oth_tab (name varchar2 (10), number of tl_id);
insert into xxc_oth_tab values('abc',,001);
insert into xxc_oth_tab values (null, null);
Wait it out put
tr_no tl_no_id name
100 222 abc
100 333
using outer joins if the two column is null? use only please of outer joins
And I tried to use outer joins on both tl_id column but not get values and I use have County (tr_no ) > 1
Rajesh123 wrote:
Thank you Kiss it is not possible to use having clause?
You need to understand the functioning of the group. If you will not be asked this question.
Check this box
SQL> select tr_no, 2 tl_no_id, 3 count(*) 4 from xxc_tr_num a, 5 xxc_od_tab b, 6 xxc_oth_tab c 7 where a.tl_number = b.tl_number(+) 8 and b.tl_id = c.tl_id(+) 9 group 10 by tr_no 11 , tl_no_id; TR_NO TL_NO_ID COUNT(*) ---------- ---------- ---------- 100 333 1 100 222 1
See what returns the count? You have grouped according to TR_NO and TL_NO_ID. You must take into consideration the TL_NO_ID just put COUNT (TR_NO) does not increase the NUMBER of the whole group. To get the NUMBER on the whole group, I used the analytical function and did. Like this, see the number of the analytical function here
SQL> select tr_no, 2 tl_no_id, 3 count(*), 4 count(*) over(partition by tr_no) 5 from xxc_tr_num a, 6 xxc_od_tab b, 7 xxc_oth_tab c 8 where a.tl_number = b.tl_number(+) 9 and b.tl_id = c.tl_id(+) 10 group 11 by tr_no 12 , tl_no_id; TR_NO TL_NO_ID COUNT(*) COUNT(*)OVER(PARTITIONBYTR_NO) ---------- ---------- ---------- ------------------------------ 100 222 1 2 100 333 1 2
So to answer your question, yes you can't do in the HAVING clause...
-
difference between two dates in the year/month/day in Obiee
Hi gurus,
I know this question have been asked and answered several times but I have a requirement that is a little different, then the previous ones.
I want to calculate the difference between two dates in OBIEE10g in year/month/day format similar to the below SQL output
SQL > select end_date, start_date,
trunc (months_between (end_date, start_date) / 12) years.
months of mod (trunc (months_between (end_date, start_date)), 12).
End_date - add_months (start_date, trunc (months_between (end_date, start_date))) days
t
Thanks in advance
SK
Search for this
"TIMESTAMPDIFF IN THE FORM OF MTHS # YEARS."
or else
To get the current mandate of employees since the date of hiring in the form of # years # mths or # year (s) # month (s)
Concat (concat (cast (TIMESTAMPDIFF (SQL_TSI_Month, "Employee attributes". (((' ' Hiring last Date employee ", CURRENT_DATE) / 12 as char),"Year (s)"), concat (cast (MOD (TIMESTAMPDIFF (SQL_TSI_Month,"Employee attributes". (((((' ' Hiring last Date employee ", CURRENT_DATE), 12) as char), 'Month (s)'))
Concat (concat (CAST (TIMESTAMPDIFF (SQL_TSI_YEAR, "Employee attributes". (((' ' Hiring last Date employee ", CURRENT_DATE) as CHAR),"Year (s)"), concat (cast (MOD (TIMESTAMPDIFF (SQL_TSI_Month,"Employee attributes". (((((' ' Hiring last Date employee ", CURRENT_DATE), 12) as char), 'Mth (s)'))
-
difference between two timestamps
Hi gurus,
I have a procedure which has 2 input parameters of type timestamp. I need to find the difference between these two stamps and be converted to a timestamp and return. Help, please
Diifernce between two timestamps is interval. You can not convert the difference between two timestamp timestamp and it makes no sense. What you expect:
25/06/2014 11:25:37.524000 - 13:07:22.987654 20/06/2014
SY.
-
Exact differences between two images
I need to be able to tell the difference between two images of a pastel artwork.
The first image is of the piece, to be hung on a wall or placed on a table.
The second is a photo of the piece after it has been moved, shaken or vibrated during which time particles were moved.
I tried superimposing the two images and see the difference between the layers. The images never seem to perfectly align along the lines of reference drawn in ink on the piece, and I do not understand the presentation of grayscale of the layer mode of difference. I would like to know if anyone has any photographic photoshopic, or insightful ideas on how to capture this specific detail of change. Another big challenge is now the images themselves to the exact distance and exposure to the room at the before and after photos, especially if they were taken in two different places on different dates.
Best I can think of is to load into Photoshop layers >, select the two layers and go Edit > auto alignment of layers. Then to the blending mode of the layer from the top to the difference.
You can test so that you know what to expect by opening an image and copy the layer of BG and setting the blending mode of the layer copied the difference. It will show as a pure black. Now make tiny changes to the upper layer.
-
How do the time difference between two dates?
Hi all
I use this query to get the time difference between two dates.
Select to_timestamp ('2012-10-03 12:00 ',' YYYY-MM-DD hh)-to_timestamp ('2012-10-03 11:00 ',' YYYY-MM-DD hh) as double diff;
but do not get the correct result.
Thank youLeft KEY... Left Padding of tanks.
-
How to find the difference between two dates in the presentation layer
Hi gurus,
Hello to everyone. Today, I came with the new requirement.
I need to know the difference between a date and the current date in the formula column application presentation layer.by.
Thank you and best regards,
PratesHi Navin,
TIMESTAMPDIFF function first determines the timestamp component that corresponds to the specified interval setting. For example, SQL_TSI_DAY corresponds to the day component and SQL_TSI_MONTH corresponds to the component "month".
If you want to display the difference between two dates in days using SQL_TSI_DAY, unlike butterflies SQL_TSI_MONTH and so on...
hope you understand...
Award points and to close the debate, if your question is answered.
See you soon,.
Aravind -
Find the difference between two date and time
Hi friends,
I wanted to find the difference between two date and time, but my qury is slightest error "invalid number."
select sql_step_num,proc_name,run_seqno,start_date,end_date,(to_char(start_date,'HH24-MI-SS') - to_char(end_date,'HH24-MI-SS') ) as ed from eval.EVAL_RUNTIME_DETAILS where trunc(start_date) = trunc(sysdate) order by sql_step_num;
You try to get the feel between two char strings.
And more difference between two dates gives a NUMBER of days.
Try this:select sql_step_num,proc_name,run_seqno,start_date,end_date,numtodsinterval(end_date-start_date,'DAY') as ed from eval.EVAL_RUNTIME_DETAILS where trunc(start_date) = trunc(sysdate) order by sql_step_num;
-
The most elegant way to get the difference between two tables - not least!
Hello
Simplified example of what I'm trying to achieve - I have two tables ORIGINAL and REVISED.
My aim is to compare the two, such as; -
When there is data in the two tables I get the difference between the Budget column, and if there is no difference, so I don't want no lines.
When data exists in the ORIGINAL, but not in review, I want to the inverse of the current value of the Budget column.
Where the data exist in REVISED I want the REVISED value.
I can see how I can do this, see below, but is there a more elegant solution?
Data for the ORIGINAL table
Data for the REVISED tableselect '801040' entity, '2186' expense_type, 234000 budget from dual union all select '801040' entity, '3001' expense_type, 1000 budget from dual union all select '801040' entity, 'P132' expense_type, 34000 budget from dual union all select '801040' entity, 'P135' expense_type, 43000 budget from dual
Desired outputselect '801040' entity, '2186' expense_type, 235000 budget from dual union all select '801040' entity, 'P132' expense_type, 34000 budget from dual union all select '801040' entity, 'P139' expense_type, 56000 budget from dual
ENTITY EXPENSE_TYPE DIFFERENCE
------ ------------ ----------
801040 2186 1000
801040 3001-1000
801040 P135-43000
801040 P139 56000
5 selected lines.
Code current to achieve this, is there a better way?
Thanks a lot for your comments,.select original.entity , original.expense_type , (nvl(revised.budget,0) - original.budget) as difference from original , revised where original.entity = revised.entity(+) and original.expense_type = revised.expense_type(+) and (nvl(revised.budget,0) - original.budget) != 0 union all select revised.entity , revised.expense_type , revised.budget as difference from revised where not exists (select 'x' from original where original.entity = revised.entity and original.expense_type = revised.expense_type) and revised.budget != 0
Robert.
Published by: Robert Angel on January 17, 2012 03:31 to change is not equal to! = - Thanks for the heads upSQL> with original 2 as 3 ( 4 select '801040' entity, '2186' expense_type, 234000 budget 5 from dual 6 union all 7 select '801040' entity, '3001' expense_type, 1000 budget 8 from dual 9 union all 10 select '801040' entity, 'P132' expense_type, 34000 budget 11 from dual 12 union all 13 select '801040' entity, 'P135' expense_type, 43000 budget 14 from dual 15 ) 16 , revised 17 as 18 ( 19 select '801040' entity, '2186' expense_type, 235000 budget 20 from dual 21 union all 22 select '801040' entity, 'P132' expense_type, 34000 budget 23 from dual 24 union all 25 select '801040' entity, 'P139' expense_type, 56000 budget 26 from dual 27 ) 28 select * 29 from ( 30 select nvl(o.entity, r.entity) entity, 31 nvl(o.expense_type, r.expense_type) expense_type, 32 nvl(r.budget,0) - nvl(o.budget,0) budget 33 from original o 34 full join revised r 35 on o.entity = r.entity 36 and o.expense_type = r.expense_type 37 ) 38 where budget <> 0 39 / ENTITY EXPE BUDGET ------ ---- ---------- 801040 2186 1000 801040 P135 -43000 801040 3001 -1000 801040 P139 56000 SQL>
-
Find the difference between two numbers (DBL)
Hi all
Is there a function in labview other than the subtraction function that can find the difference between the two numbers given?
Thank you
Davidson
-
Difference between two numbers of laptop models
Can someone tell me if there is a difference between these models of computers two laptops? As far as I can tell they are the same.
M7-j120dx and M7-J010D. Thank you.Hello
To the second machine:
http://support.HP.com/us-en/document/c03770540
You can check yourself, BUT I found at least 2 things that tell me that the first one is the best: it has screen FULL HD and better card WiFi (b/g/n a/c).
Kind regards.
-
Hello
I have two columns both of them date data types.
I would like to know the difference between these two dates.
SELECTION INTERVAL ' + 2342 23:23:23 ' DAY (4) TO THE SECOND - INTERVAL ' + 102 13:13:13 ' DAY (4) SECOND FROM DUAL;
But, I get this:
'+ 2240 10:10:10.000000'
I'd like to see the result in a year-month and jour-deuxieme groups. I can't do anything with + 2240 days...
Thanks in advance!
Hello Adme12
You can use it.
SET LINESIZE 110 PAGESIZE 20
COLUMN today FORMAT A20
COLUMN TOMORROW FORMAT A20
COLUMN YEAR_MONTHS FORMAT A15
COLUMN DAY_SEC FORMAT A30
SET ECHO ON
SELECT TO_CHAR (today, ' JJ.) MR. HH24:MI:SS' YYYY) LIKE TODAY
, TO_CHAR (tomorrow, ' JJ.) MR. HH24:MI:SS' YYYY) TOMORROW
NUMTOYMINTERVAL (MONTHS_BETWEEN (TOMORROW, TODAY), 'MONTHS') AS YEAR_MONTHS
, NUMTODSINTERVAL (TOMORROW - ADD_MONTHS (TODAY, TRUNC (MONTHS_BETWEEN (TOMORROW, TODAY))), 'DAY') AS DAY_SEC
Of
(SELECT SYSDATE + INTERVAL ' + 102 13:13:13 ' DAY (4) ON THE SECOND THAT TODAY ' HUI)
, SYSDATE + INTERVAL ' + 2342 23:23:23 ' DAY (4) ON THE SECOND TOMORROW
OF THE DOUBLE
)
;
TODAY TOMORROW YEAR_MONTHS DAY_SEC
-------------------- -------------------- --------------- ------------------------------
23.04.2014 04:49 10.06.2020 14:59:10 + 000000006-02 + 000000018 10:10:10.000000000
Of course, it is not so good that you have so many 0, but you can convert the result to a char (TO_CHAR) and you can enter.
I hope this helps you!
Kind regards
David
-
Difference between two statement.
I use 11.2.0.3 oracle version, and when I am running below pieces of code and expect similar results.
Below is the variable declare package level as below.
TYPE mycur IS REF CURSOR;
Now mentioned below is my procedure inside the package. My question is, I want to understand the difference between the following two statement in the same procedure. as as statement: 1 give me several records to pk1, where as statement: 2 gives me the good result which is recorded under the outlet of the slider back.
Statement: 1
PROCEDURE p1 (pk1 in NUMBER,
ret_cursor ON mycur)
AS
BEGIN
Open Select ret_cursor *.
A,.
b,
WHERE a.id = b.id
AND (a.c1 = b.c1
GOLD a.c2 = b.c2)
AND a.c3 = pk1;
END;
/
Statement: 2
PROCEDURE p1 (pk1 in NUMBER,
ret_cursor ON mycur)
AS
V_QUERY VARCHAR2 (4000);
BEGIN
V_QUERY: =.
"SELECT."
A,.
b,
WHERE a.id = b.id
AND (a.c1 = b.c1
GOLD a.c2 = b.c2)
AND a.c3 = ' | PK1;
Ret_cursor OPEN for V_QUERY;
END;actually my mistake, I just the reason behind the question. I had published the name of the table variable / by their and are different than real.
So the question was naming convention given by the developers, the name of the input variable looked exactly like that of the name of the column, it's why he estimated at something like 'and (1 = 1)'.The input variable name has been 'c3' as column name 'a' causing problem.
a.C3 = c3
Maybe you are looking for
-
Why can't edit my contacts to search with the new ios 10.0.1
Why can't edit my contacts to search with the new ios 10.0.1
-
How can I get Safari working again?
I've just updated my software yesterday (like being invited for a very long time) and today the 9.1.1 safari (OSX 10.9.5) repeatedly crashes on my iMac. This never happened before yesterday. I've been reluctant to update because I thought that I shou
-
show the url in the bookmarks instead of the name bar
HelloI want to ask whether it is possible to display the Url (location) in the toolbar of bookmarks instead of the name. When you right-click on an entry-> properties it shows these two fields. I want the location to display on the menu.Thank you ver
-
I have two problems. 1. After installing windows 7 ultimate my A300-1eg started to overheat and shut down.I know that BONES don't influense if laptop overheating or not, this nut the problem I have. 2. I have taken stuff on HARD drive what program sh
-
Mid-2014 MBPr has been restarted itself lately
My MBP Mid-2014 with Retina display was strange behavior in recent days. Sometimes the backlight on the keypad turns off. What is more worrying, it's suddenly the screen turns off, then after a few (or more) seconds, I get a screen indicating that