Join natural vs using the Clause
Hello everyone,
I am pretty new to SQL and Oracle and have been practicing with data sample provided with the Oracle installation.
I'm having some difficulty understanding why, when I use the following query, I have received only one result:
SELECT last_name, department_id, department_name
Ministries of NATURAL JOIN employees
WHERE department_id = 20;
-----------------------------------------------
LAST_NAME, DEPARTMENT_ID DEPARTMENT_NAME
-----------------------------------------------
Fay 20 Marketing
Yet, when I run the query below I have two results:
SELECT last_name, department_id, department_name
Employees JOIN departments USING (department_id)
WHERE department_id = 20;
-----------------------------------------------
LAST_NAME, DEPARTMENT_ID DEPARTMENT_NAME
-----------------------------------------------
Fay 20 Marketing
Hiba 20 Marketing
It was my understanding that these two queries must have generated the same results.
Out of curiosity, I also tried to run the next and received a null value for the second entry:
SELECT last_name, department_id, department_name
Ministries of NATURAL LEFT JOIN employee
WHERE department_id = 20;
-----------------------------------------------
LAST_NAME, DEPARTMENT_ID DEPARTMENT_NAME
-----------------------------------------------
Fay 20 Marketing
20 Hartstein (null)
Any help would be greatly appreciated. Thanks in advance.
Hello
I assume you mean the tables provided by Oracle in the HR schema.
HR. Employees and hr.departments have 2 columns with the same names, department_id MANAGER_ID, as well
SELECT last_name, department_id, department_name
Employees
NATURAL JOIN departments
WHERE department_id = 20;
is equivalent to
SELECT last_name, department_id, department_name
Employees
JOIN departments USING (department_id, manager_id)
WHERE department_id = 20;
In fact, I do not recommend NATURAL JOIN or USE. I think it's less confusing and more robust for use on, like this
SELECT last_name, department_id, department_name
E EMPLOYEES
JOIN departments d ON d.dpartment_id = e.department_id
AND d.manager_id = e.manager_idWHERE department_id = 20;
This isn't just my preference. Person, not literally, using NATURAL JOIN unless they are a manual writing or reading a.
Very rarely, you will see a person in the real world using the HELP, but again, it is very rare.
In both cases, they have good reasons. Save you time and forget all about NATURAL JOIN and USE.
Tags: Database
Similar Questions
-
Selection of the list of clients using the clause "EXISTS".
Dear all,
I have 3 tables, say,
TABLE1:
CUST_CODE
(PRIMARY KEY)
CUST_NAME
CUST_COUNTRY_CODE
CUST_CITY_CODE
CUST_AREA_CODE
A
CUST1
COU1
CIT1
A1
B
CUST2
COU2
CIT2
A2
C
CUST3
COU2
CIT2
A3
D
CUST4
COU3
CIT4
A4
E
CUST5
COU3
CIT5
A5
TABLE2
STOCK_SYS_ID
(PRIMARY KEY)
STOCK_CUSTOMER_CODE
STOCK_CUSTOMER_
COU_CODE
STOCK_
CUSTOMER_
CIT_CODE
STOCK_
CUSTOMER_
ARE_CODE
STOCK_DOC_
CREATED
1
A
[Leaving empty as we have reference only to the customers and the date here...]
10/15/2015
2
B
15/09/2015
3
A
16/08/2015
4
C
18/08/2015
5
E
22/07/2015
6
C
31/01/2015
7
A
15/10/2014
TABLE 3
AREA_CODE
AREA_COUNTRY_CODE
AREA_CITY_CODE
A1
COU1
CIT1
A2
COU2
CIT2
A3
COU3
CIT2
A4
COU3
CIT3
A5
COU4
CIT5
How can I find the list of clients of TABLE1, which are present in TABLE2 by 2015 and have country-city-zone, both correct mapping as specified in section TABLE3 using the clause "EXISTS".
Is that my output will be like,
CUST_CODE
(ONLY CORRECT CUSTOMER CODES)
CUST_NAME
A
CUST1
B
CUST2
Thanks in advance,
Séverine Suresh
Hello
So, you want to see 3 columns in table1 correspond to 3 columns in t3. It is not enough for only 1 column equal:
Area_Code must be equal
country_code and must be equal
city_code and must be equal.
Here's a way to encode that, by using the EXISTS operator in a WHERE clause:
SELECT cust_no, cust_name
FROM table1 t1
WHEN THERE IS)
SELECT 0
Table 3 T3
WHERE t3.area_code = t1.cust_area_code
AND t3.area_country_code = t1.cust_country_code
AND t3.area_city_code = t1.cust_city_code
)
;
I hope that answers your question.
If not, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results you want to start from these data (otherwise what you've posted already).
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: Re: 2. How can I ask a question on the forums?
-
PL/SQL parameter in fusion by using the clause
Hi all
I need to create a procedure where I use the Merge clause. However, by using the condition, I have to put value user_define (V_LOCALE_CD). This value checks table of locale and then to make a match with table of flex_labels_test.
There is no specific requirement and I don't have the test data.
My only question how do I use user set the value using the condition. Here is the procedure I created as follows.
create or replace the PROCEDURE UPSERT_FLEX_LABEL_3 (V_LOCALE_CD IN VARCHAR2,
V_VALUE IN VARCHAR2,
V_FIELDVALUE IN VARCHAR2,
V_FIELDNAME IN VARCHAR2,
V_TABLENAME IN VARCHAR2,
N_FLEX_TYPE NUMBER,
V_COLOR IN VARCHAR2 DEFAULT NULL,
N_IMAGE_LIBRARY_ID IN THE NUMBER DEFAULT NULL,
N_HIERARCHY_ID IN DEFAULT NUMBER 5237260000000000001,
N_IS_INHERITED IN THE DEFAULT NUMBER 1)
AS
L_COUNT NUMBER;
NUMBER OF N_LOCALE_ID;
NUMBER OF NN_HIERARCHY_ID: = 5237260000000000001;
NUMBER OF NN_IS_INHERITED: = 1;
NUMBER OF INSERTCOUNT;
UPDATECOUNT NUMBER;
NUMBER OF ERR_CODE;
ERR_MSG VARCHAR2 (100);
BEGIN
-SELECT ID IN N_LOCALE_ID OF PLACES WHERE LOCALE_CD = V_LOCALE_CD;
/ * IT WILL CHECK DUPLICATES, IF THEY ARE PRESENT, THEN IT WILL UPDATE RECORD ELSE IT WILL INSERT A NEW RECORD * /.
BEGIN
Merge into fl flex_labels_test
using (select locale id where locale_cd = V_LOCALE_CD) L
on (l.id = fl.locale_id)
When matched then
GAME UPDATE
HIERARCHY_ID = NVL (N_HIERARCHY_ID, NN_HIERARCHY_ID),
IS_INHERITED = NVL (N_IS_INHERITED, NN_IS_INHERITED),
FLEX_TYPE = N_FLEX_TYPE,
VALUE = V_VALUE,
IMAGE_LIBRARY_ID = N_IMAGE_LIBRARY_ID,
COLOR = V_COLOR
WHERE TABLENAME = V_TABLENAME
AND FIELDNAME = V_FIELDNAME
AND FIELDVALUE = V_FIELDVALUE
When not matched then
INSERT (HIERARCHY_ID, ID_PARAMETRES_REGIONAUX, IS_INHERITED, FLEX_TYPE, TABLENAME, FIELDNAME, FIELDVALUE, VALUE, IMAGE_LIBRARY_ID, COLOR)
VALUES (NVL (N_HIERARCHY_ID, NN_HIERARCHY_ID), N_LOCALE_ID, NVL (N_IS_INHERITED, NN_IS_INHERITED), N_FLEX_TYPE, V_TABLENAME, V_FIELDNAME, V_FIELDVALUE, V_VALUE, N_IMAGE_LIBRARY_ID, V_COLOR);
UPDATECOUNT: = NUMBER OF ROWS SQL %;
EXCEPTION
WHILE OTHERS THEN
ERR_CODE: = SQLCODE;
ERR_MSG: = SUBSTR (SQLERRM, 1, 200);
DBMS_OUTPUT. PUT_LINE ("ERRORS" |) ERR_CODE | ' AND ' | ERR_MSG);
END;
COMMIT;
DBMS_OUTPUT. PUT_LINE ('RECORD INSERTCOUNT =' |) NVL(INSERTCOUNT,0));
DBMS_OUTPUT. PUT_LINE (' UPDATECOUNT RECORD ='|) NVL(UPDATECOUNT,0));
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20001, "ID NOT FOUND REGIONAL SETTINGS");
END;
I guess that's what I was looking for. Thank you guys for your efforts.
-
Cannot be joined lines when using the line Segment tool
So unfortunately, I've updated to the latest version of Illustrator Cc (V19.2.1). And to my horror, I can no longer draw a line (with the line segment tool) then draw another line, coming from the previous those anchor point. When I try to shoot immediately. He's trying to turn the line rather than create a line joining... anyway to change that or am I stuck with it?
(Also, I use windows currently..)
http://Tinypic.com/player.php?v=iqc0mc & s = 9 #. Vr5gifJ95hE
I don't know if you can say/see/see in the video, but here's the process that I'm following departure using the line-drawing the line-> > segment trying to draw a line from that anchor point (and that is the question, when I'm doing it automatically, it assumes I want to transform the line)-> changes to the tool selection and clicks on the line to deselect-> goes back and finishes object, repeating the process.
Help me please... I'm desperate...
It is these new life forms, a few disadvantages too with the rectangle tool, ellipse etc. tool.
to go back to the old behavior
Object > shape > expand the form, do a deed for him, or do what I did a hotkey (Windows 7).
Edit > keyboard shortcuts > Menu commands > object > shape > expand the form , then in the first box to the right click in it, select and press a key on the keyboard, I choose F9, OK and name.
It's an extra step, having to have a finger on the mouse and the other on the keyboard for each line. but I can't think otherwise.
-
How to use the clause type conditionally create new lines
This question is just for learning - no object other than to start real world to create versions of some queries known to learn how to measure the performance of the MODEL clause clause of the MODEL versions.
The question is: How can you write a STANDARD clause that pivots (updates) ONLY the lines that actually need to rotate and do NOT change the lines that have no value and cannot be rotated.
I found a good site that has about two dozen example articles on different pieces. This first link is the beginning of the series.
SQL features tutorials - Clause TYPE
http://www.sqlsnippets.com/en/topic-11663.html
This link is to a clause of FAQ of BluShadow MODEL version "how to convert rows to columns."
Line - MODEL method string
http://www.sqlsnippets.com/en/topic-11987.html
The solution to this link uses this line of source:
POSITION KEY VAL
--- ---------- ----------
R08 0 v1, v2, v3,.
and this result set:
POSITION KEY VAL
--- ---------- ----------
R08 1 v1
R08 2 v2
R08 3 v3
The reason why it produces that result set is this clause of the statement of MODEL
RETURN THE UPDATED LINES
If you comment on this article, you will see that the original lines are all in position 0. This means that the solution reproduced EACH SOURCE LINE even if there is only one item in the list of values.
Thus, even a line source with a single value (for example, the r01 'a') will be updated and updated this line is returned.
For a large number of data sources with only a few lines that actually need to rotate it would be a great performance of infringement.
This is the sample data source
with t as (button 1, 'a' value 'abc' col2, col3 'def' of the double
Select Union all 2, 'b', 'ghi', 'jkl' from dual
Union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
Union all select 4, 'f', 'stu', 'vwx' from dual
)
Select the key, value, col2, col3
tKEY, VALUE, COL2, COL3
1, a, abc, def
2, b, GHI, jkl
3, "c, d, e, mno, pqr.
4, f, stu, vwxLines 1, 2 and 4 only have a value of (a, b, c respectively.
Only line 3 must rotate. It contains "c, d, e" and which must become 3 lines in the result set
Value of the key, col2 col3
1 an abc def
2B ghi jkl
3 c mno, pqr
3 d mno, pqr
3 e mno, pqr
4 f stu vwxThe nut of the problem is that if the clause 'RETURN UPDATED ROWS' is used, then the lines 1, 2 and 4 must be updated in order to be returned in the result set. And if this clause is NOT used, then line 3 must be updated by 'c', d, e 'c' and two new product lines: one line for a ' and one for 'e '.
How can you do this with the TYPE clause without the help of the clause "Return LINES UPDATE"? I don't have a solution to sample showing what I tried because I can't understand what it takes to even try.
I have a solution that uses "RETURN UPDATED ROWS" but I want to compare this performance to the exercise, when this clause is NOT used.
We ask BluShadow to add the solution of MODEL clause to this FAQ with other similar solutions.
Like this?
SQL > with t as
() 2
3 select the 1 key, 'a' val, 'abc' col2, col3 'def' of the double
Select 4 Union all 2, 'b', 'ghi', 'jkl' from dual
5 union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
Select 6 Union all the 4 'f', 'stu', 'vwx' from dual
7)
8. Select the key
9, key_1
10, val
11, regexp_substr (val, ' [^,] +', 1, key_1) val_new
12, col2
13, col3
14 t
model 15
16 partition by (key)
dimension (1 key_1) 17
18 measures (val, col2, col3, (length (val) - length (replace (val, ",")) + 1) as len)
19 rules
(20)
21 val [for 1 to increment of len key_1 [1] 1] = val [1]
22, col2 [for 1 to increment of len key_1 [1] 1] = col2 [1]
23, col3 [for 1 to increment of len key_1 [1] 1] = col3 [1]
24)
25 order
26 by key
27, key_1;KEY KEY_1 VAL VAL_N NECK NECK
---------- ---------- ----- ----- --- ---
1 1 has an abc def
2 b 1 b ghi jkl
3 1 c, d, e c mno pqr
3 2 c, d, e d mno pqr
3 3 c, d, e e mno pqr
4 1 f f stu vwx6 selected lines.
-
Update a table using the clause
Hello
I want to update a table using the selected values.
Cases in the sample:
create table as empsalary)
Select 1 as empid, 0 in the wages of all the double union
Select option 2, the double 0);
Data update are as follows
with saldata as
(
Select 1 as empid, 5000 as wages, 500 as double pf
Union of all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
I tried the following query but does not work
updated set of empsalary table (empid, salary) =
(
Select * from)
with saldata as
(
Select 1 as empid, salary, 500 5000 as pf Union double all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
) sl
where sl.empid = empsalary.empid
)
I use oracle 10g.
Help, please.
Krishna Devi wrote:
Hello
I want to update a table using the selected values.
Cases in the sample:
create table as empsalary)
Select 1 as empid, 0 in the wages of all the double union
Select option 2, the double 0);
Data update are as follows
with saldata as
(
Select 1 as empid, 5000 as wages, 500 as double pf
Union of all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
I tried the following query but does not work
updated set of empsalary table (empid, salary) =
(
Select * from)
with saldata as
(
Select 1 as empid, salary, 500 5000 as pf Union double all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
) sl
where sl.empid = empsalary.empid
)
I use oracle 10g.
Help, please.
Thanks for posting creates table and test data.
The error message would have helped because it's pretty obvious that this is the problem:
Update table empsalary
*
ERROR on line 1:
ORA-00903: invalid table name
Just remove the word "table".
-
ORA-19102: literal string XQuery waited while xmltable reading using the clause of passage
Hello
I have the following XML in the column tmp_xml in the tmp_medimail_accounts table:
" < = xmlns:env env:Envelope ' http://schemas.xmlsoap.org/SOAP/envelope/ ">
< env:Header / >
< env:Body >
" < its: findAccountByCriteriaResponse xmlns: its = ' http://session.kernel.CMP.com/ ">
< return >
< detailedInfo > accounts found: 1 < / detailedInfo >
< operationResult > MPROXY_RESULT_OK < / operationResult >
< value >
< authCertificate / >
< autocertificationActive / >
< boolAck > true < / boolAck >
< caDomain > BE_AUTO < / caDomain >
< certified > false < / certified >
< City > BELSELE < / City >
< commercialAction / >
< country / >
< description > MediMail 3.7.4 < / description >
other < dmi > < / dmi >
< emailForward > false < / emailForward >
< enabled > true < / enabled >
< encCertificate / >
medidoc < encodingType > < / encodingType >
< etk / >
< fax > LDAP this field is masked by the SECURITYFILTER < / fax >
PC < firstName > < / name >
< inami > 72091883000 < / inami >
< institution > pc sint hieronymus < / institution >
< language > NL < / language >
< name > sint-hieronymus < / lastName >
< lastconnectiondate > 20140115090051Z < / lastconnectiondate >
< localeStr / >
PC.Sint - hieronymus of < connection > < / login >
< mail > [email protected] < / mail >
< mexiAddress > pc.sint-hieronymus.72091883@BE_AUTO < / mexiAddress >
< mexiBackup / >
< mobilephone > LDAP this field is masked by the SECURITYFILTER < / mobilephone >
< niss / >
< oldIP / >
< oldSystemId > 720918 < / oldSystemId >
< packageName > M < / packageName >
This LDAP is hidden by the SECURITYFILTER field < password > < / password >
< pin / >
< pkey / >
< pkeyehealth / >
< main > false < / main >
< principalUserName / >
the province <>FLANDRE_ORIENTALE < / province >
< registrationDate > 20101213093341Z < / registrationDate >
< role > HOSPITAL < / role >
< sender > true < / sender >
< senderInvisible > true < / senderInvisible >
< subscriptiondocs > false < / subscriptiondocs >
This LDAP is hidden by the SECURITYFILTER field < phone > < / phone >
< improved / >
< userpublic / >
< usetranscodor > true < / usetranscodor >
< version / >
< / value >
< / return >
< / its: findAccountByCriteriaResponse >
< / env:Body >
< / env:Envelope >
I want to read the XML column and display it as a relational table. I have the following SQL code:
Select x.*
of tmp_medimail_accounts t
xmltable)
xmlnamespaces ('http://schemas.xmlsoap.org/soap/envelope/"as" env" )
, ' http://session.kernel.CMP.com/ ' as 'his'
)
, ' env:Envelope / env:Body / its: findAccountByCriteriaResponse return value '
in passing t.tmp_xml
path of varchar2 (30) columns "firstName", firstName
path varchar2 (30) LastName "lastName."
rizivnr varchar2 (11) path 'inami ',.
path of varchar2 (50) address "mexiAddress."
path of varchar2 (100) email "mail."
Gemeente varchar2 (50) path 'city') x;
But I have error: ORA-19102: literal string XQuery WAITED
Can someone help me?
Best regards, Hans
Hello
What is your version of the database?
It looks like an old problem related to the CURSOR_SHARING parameter.
See if the solution given here helps: How to use a web service xml document
-
How to use the clause type without hard-coding the values inside?
Query
Select acct_no,
gl_code,
CASE
WHEN entry_type_label ("earned INCOME") THEN
"Recipes".
ON THE OTHER
"Deferred income of credit."
END as entry_type_label,
CASE
WHEN entry_type_label IN ("opening balance") THEN
"Opening balance".
WHEN entry_type_label ("deferred revenue CREDIT") THEN
"The amount of the invoice.
WHEN entry_type_label ("earned INCOME") THEN
"Recipes".
WHEN entry_type_label IN ('closing balance") THEN
"Closing balance.
ON THE OTHER
"Deferred income of credit."
END tag as,
entry_type_no,
orig_chg_start_date,
period_no,
-amt as amt
of revrec_test
WHERE acct_no = 1788562
AND IN (2, 4) entry_type_no (acct_no model dimension,
gl_code,
entry_type_label,
entry_type_no,
orig_chg_start_date,
period_no) measures (amt) rules upsert
all (amt 1788562,
' NON-10011561',
"Opening balance"
2,
2 OCTOBER 17 08.30.00 AM'.
190 = 0,
AMT 1788562,
' NON-10011561',
"Closing balance."
2,
2 OCTOBER 17 08.30.00 AM'.
190 = amt 1788562,
' NON-10011561',
"Deferred income of credit."
2,
2 OCTOBER 17 08.30.00 AM'.
190 - amt 1788562,
"WON-10011561',
"Revenue."
4,
2 OCTOBER 17 08.30.00 AM'.
190,
AMT 1788562,
' NON-10011561',
"Opening balance"
2,
2 OCTOBER 17 08.30.00 AM'.
191 = amt 1788562,
' NON-10011561',
"Closing balance."
2,
2 OCTOBER 17 08.30.00 AM'.
190,
AMT 1788562,
' NON-10011561',
"Deferred income of credit."
2,
2 OCTOBER 17 08.30.00 AM'.
191 = 0,
AMT 1788562,
' NON-10011561',
"Closing balance."
2,
2 OCTOBER 17 08.30.00 AM'.
191 =.
(amt 1788562, "UNEARNED-10011561',"Opening balance", 2,")
2 October 17 08.30.00 AM', 191 + amt 1788562, "UNEARNED-10011561',
("'Revenue deferred credit', 2, 08.30.00 October 2, 17 h", 191)-amt
1788562,
"WON-10011561',
"Revenue."
4,
2 OCTOBER 17 08.30.00 AM'.
191,
AMT 1788562,
' NON-10011561',
"Opening balance"
2,
2 OCTOBER 17 08.30.00 AM'.
192 = amt 1788562,
' NON-10011561',
"Closing balance."
2,
2 OCTOBER 17 08.30.00 AM'.
191,
AMT 1788562,
' NON-10011561',
"Deferred income of credit."
2,
2 OCTOBER 17 08.30.00 AM'.
192 = 0,
AMT 1788562,
' NON-10011561',
"Closing balance."
2,
2 OCTOBER 17 08.30.00 AM'.
192 =.
(amt 1788562, "UNEARNED-10011561',"Opening balance", 2,")
2 October 17 08.30.00 AM', 192 + amt 1788562, "UNEARNED-10011561',
"Revenue deferred credit", 2, 08.30.00 2 October 17: "(, 192)-amt"
1788562,
"WON-10011561',
"Revenue."
4,
2 OCTOBER 17 08.30.00 AM'.
192,
AMT 1788562,
' NON-10011561',
"Opening balance"
2,
2 OCTOBER 17 08.30.00 AM'.
193 = amt 1788562,
' NON-10011561',
"Closing balance."
2,
2 OCTOBER 17 08.30.00 AM'.
192,
AMT 1788562,
' NON-10011561',
"Deferred income of credit."
2,
2 OCTOBER 17 08.30.00 AM'.
193 = 0,
AMT 1788562,
' NON-10011561',
"Closing balance."
2,
2 OCTOBER 17 08.30.00 AM'.
193 =.
(amt 1788562, "UNEARNED-10011561',"Opening balance", 2,")
2 October 17 08.30.00 AM', 193 + amt 1788562, "UNEARNED-10011561',
("Revenue deferred credit", 2, 08.30.00 2 October 17: ', 193)-amt
1788562,
"WON-10011561',
"Revenue."
4,
2 OCTOBER 17 08.30.00 AM'.
193)
ORDER BY period_no, entry_type_no;
The query above works fine. But I hardcoded the values. I want to do the same operation for the other account number which will have different non periodical. How can I reach it?
Thanks in advance.
And why do you need a model for that? If I understand the reqs OK:
with t as)
Select acct_no,
"U-11561' gl_code,
"Deferred income credit ' entry_type_label,.
2 entry_type_no,
orig_chg_start_date,
period_no,
Max)
case entry_type_no
When 2 then - amt
0 otherwise
end
) amt,.
Description of the "invoice."
2 weight
from table_one
Acct_no group,
orig_chg_start_date,
period_no
Union of all the
Select acct_no,
gl_code,
entry_type_label,
entry_type_no,
orig_chg_start_date,
period_no,
-amt,
Description "paid the Bill."
3 weight
from table_one
where entry_type_no = 4
Union of all the
Select acct_no,
"U-11561' gl_code,
"Deferred income credit ' entry_type_label,.
2 entry_type_no,
orig_chg_start_date,
period_no,
AMT 0,.
case lvl
When 1 then 'account opening. "
of other "close account."
description of the end,
case lvl
When 1 then 1
another 99
end weight
from table_one,.
(select level lvl from dual connect by level<=>=>
Acct_no group,
orig_chg_start_date,
period_no,
LVL
)
Select acct_no,
gl_code,
entry_type_label,
entry_type_no,
orig_chg_start_date,
period_no,
case
what weight (sum) (1.99) can
case weight
When 2 then amt
When 3 then - amt
0 otherwise
end
)
During)
acct_no partition
order of period_no,
weight
)
AMT else
AMT of end,
Description
t
order of acct_no,
period_no,
weight
/
ACCT_NO GL_CODE ENTRY_TYPE_LABEL ENTRY_TYPE_NO ORIG_CHG_START_DATE PERIOD_NO AMT DESCRIPTION
------- ---------------------------- ----------------------- ------------- --------------------- --------- ---------- ---------------
1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 100 0 opening account
1001 U-11561 deferred revenue credit 2 Bill October 2, 17 08.30.00 AM 100 44
E-11561 1001 recipes 4 08.30.00 2 October 17: 100 13.87 paid invoice1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 100 30.13 closing account
1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 101 30.13 opening account
1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 101 0 Bill
E-11561 1001 recipes 4 08.30.00 2 October 17: 101 14,35 paid invoice1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 101 15.78 closing account
1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 102 15.78 opening account
1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 102 Bill 0
E-11561 1001 recipes 4 08.30.00 2 October 17: 102 14.83 invoice paid1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 102.95 close account
1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 103.95 opening account
1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 103 Bill 0
E-11561 1001 recipes 4 08.30.00 2 October 17: 103.95 invoice paid1001 U-11561 deferred revenue credit 2 2 October 17 08.30.00 AM 103 0 closing account
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 104 0 opening account
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 60 104 Bill
1002 fixed costs recurring revenue COA Code 4 09.30.00 November 17, 13 h 104 9.13 invoice paid1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 104 50.87 closing account
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 105 50.87 opening account
1002 U-11561 deferred revenue credit 2 December 20, 13 09.30.00 AM 105 50.87 opening account
1002 U-11561 deferred revenue credit 2 09.30.00 December 20, 13 h 105 19.24 invoice
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 105 0 Bill
1002 fixed costs recurring revenue COA Code 4 09.30.00 November 17, 13 h 105 44,91 paid invoice1002 fixed costs recurring revenue COA Code 4 December 20, 13 09.30.00 AM 105 - 7.82 Bill paid
1002 fixed costs recurring revenue COA Code 4 09.30.00 December 20, 13 h 105 3.93 invoice paid
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 105 29.09 closing account
1002 U-11561 deferred revenue credit 2 December 20, 13 09.30.00 AM 105 29.09 closing account
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 106 29.09 opening account
1002 U-11561 deferred revenue credit 2 December 20, 13 09.30.00 AM 106 29.09 opening account
1002 U-11561 deferred revenue credit 2 December 20, 13 09.30.00 AM 106 0 Bill
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 106 0 Bill
1002 fixed costs recurring revenue COA Code 4 09.30.00 November 17, 13 h 106 44,91 paid invoice1002 fixed costs recurring revenue COA Code 4 09.30.00 December 20, 13 h 106 11.75 invoice paid
1002 fixed costs recurring revenue COA Code 4 December 20, 13 09.30.00 AM - 23.47 106 paid
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 106-4.1 closing account
1002 U-11561 deferred revenue credit 2 December 20, 13 09.30.00 AM 106-4.1 closing account
1002 U-11561 deferred revenue credit 2 December 20, 13 09.30.00 AM 107 - 4.1 opening account
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 107 - 4.1 opening account
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 107 Bill 0
1002 U-11561 deferred revenue credit 2 December 20, 13 09.30.00 AM 107 Bill 0
1002 fixed costs recurring revenue COA Code 4 December 20, 13 09.30.00 AM - 13.69 107 paid invoice1002 fixed costs recurring revenue COA Code 4 November 17, 13 09.30.00 AM 107 35.91 invoice paid
1002 fixed costs recurring revenue COA Code 4 09.30.00 20 December 13 AM 107 6,86 invoice paid
1002 U-11561 deferred revenue credit 2 17 November 13 09.30.00 AM 107 - 33.18 closing account
1002 U-11561 deferred revenue credit 2 December 20, 13 09.30.00 AM 107 - 33.18 closing account47 selected lines.
SQL >
SY.
-
Cases identified in a clause Where using the clause
Oracle Database 11 g Release 11.2.0.1.0 - 64 bit Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
Hello
I have an APEX application I need to build a SQL statement to a LOV (list of values). I hid filed that contains the type of customer that may be an 'R' or 'B '. The query must be able to display two sets of different results depending on the type of customer 'R' or 'B '.
If the customer type is 'R', then:
If the customer type is 'B', then:SELECT drg_descr d, drg_code r FROM distance_ranges WHERE drg_min_miles IN (0,5) ORDER BY drg_min_miles
Can someone help me with what I think should be a case statement?SELECT drg_descr d, drg_code r FROM distance_ranges WHERE drg_min_miles IN (0,5,10,15,20) ORDER BY drg_min_miles
Thank you
JoeTry,
SELECT drg_descr d, drg_code r FROM distance_ranges WHERE ( (drg_min_miles IN (0, 5) AND param_cust_type = 'R') OR (drg_min_miles IN (0, 5, 10, 15, 20) AND param_cust_type = 'B')) ORDER BY drg_min_miles
G.
-
The sql statement is
Select ename, job
from emp, dept
where emp.deptno = dep.deptno
and emp.deptno = 10
Union
Select ename, job
from emp, dept
where emp.deptno = dep.deptno
and emp.deptno = 20
the statement above using the WITH Clause
WITH dept10 AS
(select ename, job, hiredate, sal, comm, dname, emp.deptno
from emp, dept
where emp.deptno = dept.deptno
and emp.deptno = 10)
dept20 AS
(select ename, job, hiredate, sal, comm, dname, emp.deptno
from emp, dept
where emp.deptno = dept.deptno
and emp.deptno = 20)
SELECT *.
OF dept10
UNION
SELECT *.
OF dept20
Correct me if I'm wrong...
Thank youHello
SeenuGuddu wrote:
the Question is how u would provide the statement above by using the ClauseThe answer is that the question is meaningless. You will not use a WITH clause for this work.
Because you must use a WITH clause to get the same results as the first query, I think the best way would be:
WITH unnecessary_sub_query AS ( select DISTINCT ename, job -- , hiredate, sal, comm, dname,emp.deptno -- these columns are not in the original query from emp , dept where emp.deptno = dept.deptno and emp.deptno IN (10, 20) ) SELECT * FROM unnecessary_sub_query;
is this correct using Clause WITH or correct me
No, it's not ok to make queries more complex or slow they need to do.
In addition to the extra columns, it seems that the second query that you posted (the one who has a WITH clause) produces the same results as the first request. -
Joins of tables in the inventory
Hi all
Can you please give me the join conditions (request format as where to use an outer join or internal)?
mtl_material_transactions,
mtl_system_items_b,
mtl_parameters
mtl_item_locations,
mtl_serial_numbers,
mtl_lot_numbers
Here's the sql code.
We do not have the serial controlled items so I have all the data to validate this sql.
You need to add a large number of columns in the place where clause change conditions.
each table has some kind of column field or flag status.
You can figure that out based on the configuration of your company.
======
Select * from
mtl_material_transactions mmt,
MSI mtl_system_items_b,
mtl_parameters mp,
mil mtl_item_locations
mtl_serial_numbers msn,
mtl_lot_numbers CHF million
where
MMT.inventory_item_id = msi.inventory_item_id
and
MMT.organization_id = msi.organization_id
and
MMT.organization_id = mp.organization_id
and
-Outer join MIL incase you don't have parameters of Articles Locators
MMT.inventory_item_id = mil.inventory_item_Id
and
MMT.organization_id = mil.organization_id
and
-an outer join on MSN snack items are not control series
MMT.inventory_item_id = msn.inventory_item_id
and
MMT.organization_id = msn.current_organization_id
and
-an outer join on mln point snack is not the outer join
MMT.inventory_item_id = mln.inventory_item_id
and
MMT.organization_id = mln.organization_id
-settings
and msi.segment1 = «& itemnumber»
and mmt.organization_id = &org_id;
=====================
NOTE: not all run great sql open, it will never be over. Having so many outer joins will not use the index unless you spend in the settings I have used at least.
all the best.
-
Update a record questioned using the parameter
Hi all
Have someone to help me to update an interviewed record of forms. It's like that when I use ID to search for the details, I want to update the record you are searching.
ArifHi Arif,
Here you're doing something complicated with you.1 UCID_PARAM and USERCREATION are 2 revenge in the same form
2 UCID_PARAM contain column UCID which is the primary key of the table usercreation. I used this block to passThe blockk UCID_PARAM here is the database block and why you must pass the value as a parameter because as you say it is primary key and foreign key in the block. Then why do you use search mechanism Assembly. I mean just create relationship between UCID_PARAM and USERCREATION block or if he joins then just use the method ENTER_QUERY and EXECUTE_QUERY. I understand because if you enter a value in the UCID_PARAM block and goes to the block of detail and do EXECUTE_QUERY by selecting a WHERE CLAUSE.
So, what's going to happen here. System takes into account that you are inserting record in UCID_PARAM. So, there is a field that is not null, then the error is coming.
Just use the default behavior of your forms. Or if you really want to use this method. Next, create a block of data non-base to pass the parameter. Do not use UCID_PARAM as the database block.
And one more thing, I noticed in your this clause
set_block_property ('USERCREATION', onetime_where, 'UCID =' |) ': UCID_PARAM. UCID');
It should be
set_block_property('USERCREATION',onetime_where,'UCID='||:FORM_FIELD_NAME);
I hope it is clear now.
-Clément
-
Hello
Oracle version: 11.1.0.7.0 - 64 bit
I read the documentation online at joins. The page is avialable here: joins at
My question is about the join order of evaluation of the conditions in clause and the conditions of those
are not the join conditions and are placed in the WHERE clause.
Consider the following pseudocode
SELECT
T1. Col1,
T2.Col1
Of
Table1 t1 LEFT OUTER JOIN table2 t2
WE
(condition_expression1)
WHERE
(condition_expression2)
Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article?
Thanks in advance,
Hello
dariyoosh wrote:
Hello
Oracle version: 11.1.0.7.0 - 64 bit
I read the documentation online at joins. The page is avialable here: joins at
My question is about the join order of evaluation of the conditions in clause and the conditions of those
are not the join conditions and are placed in the WHERE clause.
Consider the following pseudocode
SELECT
T1. Col1,
T2.Col1
Of
Table1 t1 LEFT OUTER JOIN table2 t2
WE
(condition_expression1)
WHERE
(condition_expression2)
Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article? ...
The reverse is actually closer to the truth, but we can't really make general statements like that.
SQL is not a language of the proceedings. Looking at the code SQL, we could say that the code does, but we cannot say much about how that code it. In other words, SQL is a language that describes the results you get, not the way to get them.
The optimizer will do everything what he thinks is faster if it does not change the results. If any order in which they are applied (in outer joins or CONNECT BY queries, for example), then think of the join is done first, and the value of the WHERE clause is applied to the result of the join.
Here is a query looks very much like you posted:
SELECT d.deptno
e.ename, e.sal
OF scott.dept d
LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno
WHERE e.sal > = 3000
ORDER BY d.deptno
;
Output:
DEPTNO ENAME SAL
---------- ---------- ----------
10 KING 5000
20 FORD 3000
20 3000 SCOTT
The scott.dept table contains deptnos 30 and 40; Why are they not in the result set? The query behaves as if the outer join is made first (production 15 rows), then the WHERE clause has been applied. All lines with deptno = 30 had sals down han 3000 and all single line with deptno = 40 was NULL in the sal column, then these lines are excluded (as well as other lines of deptnos 10 and 20), and only 3 lines above are left.
-
From what I've been reading is preferable to use the new syntax (don't know how is it news)
The ANSI join syntax was new to Oracle in Oracle 8i in 1998 - that is 15 years old.
It can produce more readable code and is also much more readable and less human-source of errors for outer joins.
The ANSI format allows an outer join between several tables in a way the old (+) syntax specific to oracle does not and introduced the JOIN FULL OUTER you should use very rarely.
You should not use NATURAL JOIN in code - add columns not related to the tables involved can give very different results.
There have not been important bugs for ANSI joins in Oracle from Oracle 10.2 set up about 8 years ago.
As Paul says, the part on should be the criteria to join between the tables. Did clause should be the filtering of the joined tables.
So assuming start_date and end_date in_property_id are variable
SELECT resv_num, unit_date
OF p_resv_unit ru
INNER JOIN p_pm_unit_night pun
ON pun.resv_unit_id = ru.resv_unit_id
WHERE pun.property_id = in_property_id
AND pun.unit_date BETWEEN start_date AND end_date
AND pun.pm_unit_num = cvUnitNum;
If start_date and end_date are the columns of p_resv_unit the query would be:
SELECT resv_num, unit_date
OF p_resv_unit ru
INNER JOIN p_pm_unit_night pun
ON pun.resv_unit_id = ru.resv_unit_id AND pun.unit_date BETWEEN ru.start_date AND ru.end_date
WHERE pun.property_id = in_property_id
AND pun.pm_unit_num = cvUnitNum;
Inner join queries work with criteria in the wrong place, but they are harder to read. Outer joins do not work unless you put the criteria in the right place.
-
Hi all
on the 11g R2,.
How to rewrite the following using OUTER JOIN:
SELECT Ouvrages.*, exemplaires.numero
Books, best
WHERE the ouvrages.isbn = exemplaires.isbn;
Thank you
Hello
user10274093 wrote:
Hi all
on the 11g R2,.
How to rewrite the following using OUTER JOIN:
SELECT Ouvrages.*, exemplaires.numero
Books, best
WHERE the ouvrages.isbn = exemplaires.isbn;
Thank you
The query you posted is an inner join. Outer join will not give the same results.
Which type of outer join you want?
- A version that includes all the lines of the works, even if they have no corresponding row in the copies
- A version that includes all the lines of the copies, even if they have no corresponding row in the works
- A version that includes all rows from both tables, even if they have no corresponding row in the other table
If you want to than option 1 (all lines of books, even if they have no corresponding row in the copies), and then
SELECT Ouvrages.*, exemplaires.numero
Books
LEFT OUTER JOIN best ON ouvrages.isbn = exemplaires.isbn
;
If you would like option 2, then first put copies into the FROM clause.
If you would like option 3, then use FULL OUTER JOIN instead of LEFT OUTER JOIN.
I hope that answers your question.
If this isn't the case, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: Re: 2. How can I ask a question on the forums?
Maybe you are looking for
-
Everytime I try to log in to Skype, it won't let me log on and just said "Can Skype can't Connect." At first I thought I was putting in my password or something, so I changed it, but that did not help. Then, I thought it would work only if I tried a
-
Satellite C855-2HW guard go to sleep / hibernation
I have a Satellite C855 2HW and it keeps going standby / hibernation.I put everything as maximum performance and never to Hibernate, but he remains in hibernation. I do not use the Eco utility (it is off).My power cable is attached and I have it conf
-
I have the HDR-CX100 camcorder. Last summer on vacation, I recorded 32 GB of video and it installs on my netbook. Now the problem is that I can not burn these videos on DVD more.Why?First of all I didn't I need to use strictly PMB program to do this.
-
How will I know if my Windows 7 Home Premium x 64 or x 86?
I have a 64-bit computer, but there are files on the C drive for Program Files and Program Files (x 86). I have questions on this topic, but do not actually need to know, so far. I'm trying to restore my backup files in when I upgraded Vista to Windo
-
It happened two days earlier. When I start my PC, my desktop wallpaper becomes black and I get the message that is mentioned in the question. Please help me get rid of this problem. Thank you