Do not repeat with a LEFT JOIN QUERY question
HelloI would like to know how to display the following results:
*Name*: John Fox
*Sales:* 1- LAPTOP
2- HARDDRIVE
3- COMPUTER
Here's my 2 tables: CUSTOMER and SALESCUSTOMER
_________________
ID NAME GENDER
1 John Mayer F
2 Melissa John F
3 Julie Black F
4 Mickael Fox M
5 John Fox M
SALES
_________________________
ID ID_CUSTOMER TYPE
1 1 Boat
2 1 TV
3 4 CD PLAYER
4 5 LAPTOP
5 5 HARDDRIVE
6 5 COMPUTER
My QUERYSELECT customer.Name as NAME, customer.Gender, sales.TYPE
from customer
LEFT JOIN sales
ON customer.ID = sales.ID_CUSTOMER
WHERE customer.Name = 'John Fox'
The problem: if I use the default template, I have:NAME GENDER TYPE
John Fox M LAPTOP
John Fox M HARDDRIVE
John Fox M COMPUTER
I don't want the name of John Fox being repeated in each row.I tried to add: #Name # in the DEFINITION of the REGION - REGION HEADER, but I have this result:
#NAME#
NAME GENDER TYPE
John Fox M LAPTOP
John Fox M HARDDRIVE
John Fox M COMPUTER
So, what can I do to get this result? Change the query?Name: John Fox
Sales: 1- LAPTOP
2- HARDDRIVE
3- COMPUTER
Thank youRoseline
Roseline salvation,
You can adapt the solution suggested in this post Re: more than 1 records in a single cell
Thank you
Manish
Tags: Database
Similar Questions
-
Left join with three-table join query
I am trying to create a query that left me speechless. Most of the query is simple enough, but I have a problem I do not know how to solve.
Background:
We have stock stored in i_action.
We have the attributes available for each type of action. The attributes available for each action are described in shared_action_attribute. Each type of action can have three attributes or none at all.
We have the values stored for the attributes in i_attribute_value.
An example says:
We have a transfer action (action_code B4). The action of B4 entry into i_action records the fact that the transfer took place and the date at which he spoke. The attributes available for a transfer action are the function code receiver, the receiving unit number and the reason of transfer code. These types of attributes available and their order are stored in shared_action_attribute. The actual values of the attributes for a specific action of transfer are stored in i_attribute_value.
Now i_action and i_attribute_value can be connected directly in action_seq in i_action and ia_action_seq in i_attribute_value. A left join on these two tables provides results for all actions (including actions that have no attributes) and assign values (see Query 1 below).
There are two questions. First of all, I want only the first two attributes. To specify the attributes of the first two, I also i_attribute_value a link to shared_action_attribute (which is where the order is stored). I can build a simple query (without the left join) which connects the three tables, but then shares without attributes would be excluded from my result (see Query 2 below).
The second problem is that I'd actually a row returned for each action with first_attribute and second_attribute in the form of columns instead of two lines.
The final query will be used to create a materialized view.
Here are the tables and examples of what is stored in the:
TABLE i_action
Name Type
----
ACTION_SEQ NUMBER (10)
DATE OF ACTION_DATE
ACTION_CODE VARCHAR2 (3)
VARCHAR2 (1) DELETED
EXAMPLE OF LINES
ACTION_SEQ ACTION_DATE DELETED ACTION_CODE
----
45765668 9 OCTOBER 09 B2 HAS
45765670 9 OCTOBER 09 BA HAS
45765672 B6 9 OCTOBER 09A
45765673 9 OCTOBER 09 B4 HAS
45765674 9 OCTOBER 09 G1 HAS
45765675 9 OCTOBER 09 M3 HAS
TABLE i_attribute_value
Name Type
---
IA_ACTION_SEQ NUMBER (10)
SACTATT_SACT_CODE VARCHAR2 (3)
SACTATT_SAT_TYPE VARCHAR2 (3)
VARCHAR2 VALUE (50)
EXAMPLE OF LINES
IA_ACTION_SEQ SACTATT_SACT_CODE SACTATT_SAT_TYPE VALUE
----
45765668 B2 COA 37 B
45765670 BA ROA D
45765670 BA ROR P
45765672 B6 CAT C
B4 45765673 RFC E
45765673 B4 TRC P
B4 45765673 RUN 7
45765674 G1 SS 23567
G1 45765674 ASG W
TABLE shared_action_attribute
Name Type
---
SACT_CODE VARCHAR2 (3)
SAT_TYPE VARCHAR2 (3)
ORDER NUMBER (2)
TITLE VARCHAR2 (60)
EXAMPLE OF LINES
SACT_CODE SAT_TYPE UNDER THE ORDER
----
B2 ACO 1 Office code
BA ROR 1 reason to re-open
Authority of BA ROA 2 reopen
B6 CAT 1 category
B4 RFC 1 reception function code
B4 RUN 2 receives the unit code
B4 TRC 3 transfer of reason code
Sequence of G1 SS 1 personal
Reason for G1 ASG 2 assignment
QUERY 1:
It's my current query as well as its results. Most are select simple but only one column is filled using the function analytic last_value (thank you guys). The last column in the view sub stores the value of the attribute. What I want is to replace this single column with two columns named first_attribute and second_attribute and eliminate all other attributes.
SELECT ia.action_seq, ia.action_date, ia.action_code cod,
NVL
(LAST_VALUE (CASE
WHEN ia.action_code = "G1".
AND iav.sactatt_sat_type = 'SS '.
THEN THE VALUE
WHEN ia.action_code IN ('A0', 'A1')
THEN '67089'
END IGNORE NULLS
) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
IA.serial_number, ia.action_seq),
'67089'
) staff_seq,.
value
From i_action LEFT JOIN i_attribute_value iav AI
ON iav.ia_action_seq = ia.action_seq
WHERE ia.deleted = 'A ';
ACTION_SEQ ACTION_DA COD STAFF_SEQ VALUE
----
45765668 9 OCTOBER 09 B2 67089 37 B
45765670 9 OCTOBER 09 BA D 67089
45765670 9 OCTOBER 09 BA 67089 P
45765672 9 OCTOBER 09 B6 67089 C
45765673 9 OCTOBER 09 B4 67089 E
45765673 9 OCTOBER 09 B4 67089 P
45765673 9 OCTOBER 09 67089 7 B4
45765674 9 OCTOBER 09 23567 23567 G1
45765674 9 OCTOBER 09 G1 23567 W
45765675 9 OCTOBER 09 M3 23567
QUERY 2:
This query is limited to the first two attributes but he also filed actions which have no attributes, and it creates still several lines for each action instead of a single line with two columns for attributes.
SELECT ia.action_seq, ia.action_date, ia.action_code cod,
NVL
(LAST_VALUE (CASE
WHEN ia.action_code = "G1".
AND iav.sactatt_sat_type = 'SS '.
THEN THE VALUE
WHEN ia.action_code IN ('A0', 'A1')
THEN '67089'
END IGNORE NULLS
) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
IA.serial_number, ia.action_seq),
'67089'
) staff_seq,.
value
OF shared_action_attribute saa, ims_action AI, ims_attribute_value iav
WHERE iav.ia_action_seq = ia.action_seq
AND iav.sactatt_sact_code = saa.sact_code
AND iav.sactatt_sat_type = saa.sat_type
AND saa.display_order IN ('1 ', ' 2')
AND ia.deleted = 'A ';
ACTION_SEQ ACTION_DA VALUE OF COD
----
45765668 9 OCTOBER 09 B2 67089 37 B
45765670 9 OCTOBER 09 BA D 67089
45765670 9 OCTOBER 09 BA 67089 P
45765672 9 OCTOBER 09 B6 67089 C
45765673 9 OCTOBER 09 B4 67089 E
45765673 9 OCTOBER 09 67089 7 B4
45765674 9 OCTOBER 09 23567 23567 G1
45765674 9 OCTOBER 09 G1 23567 W
I found it quite complex to try to write - I hope that I was clear.
Thank you very much!Hello
You can use an alias for column (such as staff_seq) in the ORDER BY. Unfortunately, it's the only place where you can use it in the same query, where it was defined.
You can use it anywhere in the super-requetes, however, so you can still work around this problem in assigning the aliases in a subquery and GROUP BY (or other) in a Super query, like this:WITH ungrouped_data AS ( SELECT ia.action_seq, ia.action_date, ia.action_code, NVL (LAST_VALUE (CASE WHEN ia.action_code = 'G1' AND sactatt_sat_type = 'SS' THEN VALUE WHEN ia.action_code IN ('A0', 'A1') THEN '67089' END IGNORE NULLS ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date, ia.action_seq), '67089' )staff_seq, (CASE WHEN display_order = '1' THEN VALUE END) first_attribute, (CASE WHEN display_order = '2' THEN VALUE END) second_attribute FROM i_action ia LEFT JOIN i_attribute_value iav ON iav.ia_action_seq = ia.action_seq LEFT JOIN shared_action_attribute ON sactatt_sact_code = sact_code AND sactatt_sat_type = sat_type WHERE ia.deleted = 'A' ) SELECT action_seq , action_date , action_code , staff_seq , MIN (first_attribute) AS first_attribute , MIN (second_attribute) AS second_attribute FROM ungrouped_data GROUP BY action_seq , action_date , action_code , staff_seq ;
There are other alternatives for special cases, but none of them work in this particular case.
-
Need help with a self-join query
Hello
I have A table with the following data
OID parent_oid
4 of 10
4 2
2 2
12 6
6 6
parent_oid is the parent of the oid. I would like a query that displays the final parent of the oid. The result must indicate the following
Final parent OID
2 of 10
4 2
2 2
12 6
6 6
I use Oracle 10 g. I am familiar with free joins, but that alone will not do the job. Thank you!Hello
arizona9952 wrote:
... I am familiar with free joins, but that alone will not do the job.You are absolutely right!
A self-join 2-way would work for lines have no parent, or lines which are directly related to their final ancestor (such as the oid = 4), but not for what anyone further.
A 3-way self-join would work to a level more away from the last row, but no more. That would be enough with the small set of sample data that you posted, but it won't work if you have added a new rank parent_id = 10.
An N - way self-join would work for up to N + 1 levels, but no more.You need something that can go to any number of levels, such as CONNECT BY:
SELECT CONNECT_BY_ROOT oid AS oid , parent_oid AS final_parent FROM a WHERE CONNECT_BY_ISLEAF = 1 CONNECT BY oid = PRIOR parent_oid AND oid != parent_oid ;
Published by: Frank Kulash, February 22, 2010 19:09
On sober reflection, I think that a request from top down, as one below, would be more effective than a motion up and down, like the one above:
SELECT oid , CONNECT_BY_ROOT parent_oid AS final_parent FROM a START WITH parent_oid = oid CONNECT BY parent_oid = PRIOR oid AND oid != PRIOR oid ;
-
Hello
I'm having a problem with the left join query, when I join table a two table based on column task1 I get duplicate in table1.task1, table1.price.
Table1. Task1 Table1. Price table2. Task1 table2. Resource table2. Price 001 100 001 A 50 001 100 001 B 250 How can I make a request to get a result as below.
Table1. Task1 Table1. Price table2.Task2 table2. Resource table2. Price 001 100 001 A 50 001 B 250 Thank you.
Note that your query uses an inner join. Your original question mentioned a join left, generally interpreted as meaning a left OUTER join.
Anyway, according to Frank, you can use the BREAK command in SQL * Plus for the goal sought through formatting. You can also use an analytical function as Roger suggests. I think ROW_NUMBER() might do the trick, but we must be clear about the criteria for partitioning and ordering the results, for example
WITH table1 AS ( SELECT '001' AS task1 , 100 AS price FROM dual ), table2 AS ( SELECT '001' AS task1 , 'A' AS resources , 50 AS price FROM dual UNION ALL SELECT '001' AS task1 , 'B' AS resources , 250 AS price FROM dual ) SELECT DECODE(ROW_NUMBER() OVER (PARTITION BY t1.task1, t1.price ORDER BY t2.resources, t2.price),1,t1.task1) AS task1_alt , DECODE(ROW_NUMBER() OVER (PARTITION BY t1.task1, t1.price ORDER BY t2.resources, t2.price),1,t1.price) AS price_alt , t2.task1 AS task_with_resource , t2.resources , t2.price FROM table1 t1 INNER JOIN table2 t2 ON t1.task1 = t2.task1 ORDER BY t1.task1, t1.price, t2.resources, t2.price;
-
Hey everybody!
I have some difficulty in trying to create a SQL query.
I have the following tables:
-Table Products: Product list
CREATE TABLE (PRODUCTS)
PRODUCT_ID INTEGER NOT NULL,
KEY ("PRODUCT_ID") PRIMARY CONSTRAINT 'PK_PRODUCTS '.
);
-Orders table: Decreed this product
CREATE TABLE ORDERS)
ORDER_ID INTEGER NOT NULL,
PRODUCT_ID INTEGER NOT NULL, / * FK PRODUCTS (PRODUCT_ID) * /.
KEY ("ID_PEDIDO") PRIMARY CONSTRAINT 'PK_ORDERS '.
);
-Orders_Approval table: register when an order is approved
CREATE TABLE ORDERS_APPROVAL)
ORDER_ID INTEGER NOT NULL, / * FK ORDERS (ORDER_ID) * /.
APPROVAL_DATE DATE NOT NULL,
USER_ID INTEGER,
KEY("ORDER_ID","APPROVAL_DATE") PRIMARY CONSTRAINT 'PK_ORDERS_APPROVAL '.
);
-Table Orders_ApprovalData: Register more details on the amenities of the order
CREATE TABLE ORDERS_APPROVAL_DETAILS)
APPROVALDET_ID INTEGER NOT NULL,
ORDER_ID INTEGER NOT NULL, / * FK ORDERS_APPROVAL (ORDER_ID) * /.
APPROVAL_DATE DATE NOT NULL, / * FK ORDERS_APPROVAL (APPROVAL_DATE) * /.
KEY ("APPROVALDET_ID") PRIMARY CONSTRAINT 'PK_ORDERS_APPROVAL_DETAILS '.
);
The thing is that an order may OU cannot be approved. Thus, there could be no record of an order in ORDERS_APPROVAL.
In addition, an order can have more than one approval.
Here is the data that I use:
/===========\
| PRODUCTS |
|===========|
| PRODUCT_ID |
|===========|
| 1.
|===========|
| 2.
|===========|
| 3.
\===========/
/========================\
| ORDERS |
|========================|
| ORDER_ID | PRODUCT_ID |
|===========|============|
| 27. 1.
|===========|============|
| 28. 2.
|===========|============|
| 29. 3.
\===========|============/
/=========================================\
| ORDERS_APPROVAL |
|=========================================|
| ORDER_ID | APPROVAL_DATE | USER_ID.
|===========|================|============|
| 27. 01/10/2009 | 56.
|===========|================|============|
| 27. 04/10/2009 | 96.
|===========|================|============|
| 29. 03/10/2009 | 77.
\===========|================|============/
/=============================================\
| ORDERS_APPROVAL_DETAILS |
|=============================================|
| APPROVALDET_ID | ORDER_ID | APPROVAL_DATE |
|================|===========|================|
| 1. 27. 01/10/2009 |
|================|===========|================|
| 2. 27. 04/10/2009 |
|================|===========|================|
| 3. 29. 03/10/2009 |
\================|===========|================/
I need to create a query that returns the data in all tables, but for orders with more than one certification,
the query must return only the last record. It is also necessary return orders that have not yet been approved.
My first query looked like this:
SELECT
*
Of
ORD IN ORDERS,
PRODUCT PROD,
ORDERS_APPROVAL ORDAPPROV,
ORDERS_APPROVAL_DETAILS ORDAPPDET
WHERE
PROD. PRODUCT_ID = DSB. PRODUCT_ID
AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE
PS: I use the Oracle 8 syntax because it's the server I'll use. In addition, I can't change the design of database.
This query returns the data in table all. Because I used LEFT JOIN "(+)" to join the table orders_approval with the orders table, I am able to see even the orders with no approval.
But this way, I see also two approvals for order 27 (with the data above, this order was approved twice). I need to reach my paintings in the last approval for each order is but should be a left join so I can see the orders with no approval.
I tried this way:
SELECT
*
Of
ORD IN ORDERS,
PRODUCT PROD,
ORDERS_APPROVAL ORDAPPROV,
ORDERS_APPROVAL_DETAILS ORDAPPDET
WHERE
PROD. PRODUCT_ID = DSB. PRODUCT_ID
AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
--Also added the line below
AND ORDAPPROV. APPROVAL_DATE = (SELECT MAX (APPROVAL_DATE) OF ORDERS_APPROVAL WHERE THE ORDER_ID = ORDAPPROV. ORDER_ID)
AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE
But in this way, as I am specifying I want only records with approval equal to date at the latest for each order, I do not see the order without approval.
I tried again, with a left join like this:
SELECT
*
Of
ORD IN ORDERS,
PRODUCT PROD,
ORDERS_APPROVAL ORDAPPROV,
ORDERS_APPROVAL_DETAILS ORDAPPDET
WHERE
PROD. PRODUCT_ID = DSB. PRODUCT_ID
AND ORDAPPROV. ORDER_ID (+) IS DSB. ORDER_ID
--Also added the line below
AND ORDAPPROV. APPROVAL_DATE (+) = (SELECT MAX (APPROVAL_DATE) OF ORDERS_APPROVAL WHERE THE ORDER_ID = ORDAPPROV. ORDER_ID)
AND ORDAPPDET. ORDER_ID (+) IS ORDAPPROV. ORDER_ID
AND ORDAPPDET. DATA_APPROVAL_DATE (+) IS ORDAPPROV. APPROVAL_DATE
But I get a syntax error. Oracle said that it is not possible to do a join with a subquery.
If anyone knows how I can bring all this data?
Thanks in advance.
Published by: user9936895 on 05/10/2009 09:42: tried to fix the predetermined data schema.Hello
Welcome to the forum!
A scalar, such as subquery
(SELECT MAX(APPROVAL_DATE) FROM ORDERS_APPROVAL WHERE ORDER_ID=ORDAPPROV.ORDER_ID)
is allowed in a WHERE clause, but not as a condition of outer join, as you discovered.
A workaround is the query expression so that it is not part of the outer join condition, which invlove in May (as in this case), adding another subquery. In the following query, the table of orders_approval in your original OF Division is replaced with online view, which uses the exact same scalar subquery in the WHERE clause. The online display will only contain one line per order_id (assuming that there is no link with for last approval_date).
SELECT * FROM orders ord, products prod, ( -- Begin in-line view ORDAPPROV of last approval_date only SELECT * -- or list the columns needed in main query FROM orders_approval oa WHERE approval_date = ( SELECT MAX (approval_date) FROM orders_approval WHERE order_id = oa.order_id ) ) ordapprov, orders_approval_details ordappdet WHERE prod.product_id = ord.product_id AND ordapprov.order_id (+) = ord.order_id AND ordappdet.order_id (+) = ordapprov.order_id AND ordappdet.approval_date (+) = ordapprov.approval_date ;
Thank you for including CREATE TBAL statements; It is very useful.
You want to be even more useful in the future? Post INSERT statements for the sample data. That will make it easier for people to respond and easier for them to test their ideas. -
Having trouble getting my head around that, so would appreciate any help.
I run the query below, which includes a join. If I run this query through Navicat (for those who don't know, a MySQL GUI) - I get the expected result.
I also have a similar query running on the site elsewhere with success, so I am struggling to understand why it does not work.
The request is;
< name cfquery = "getwatched" datasource = "#datasource #" >
SELECT r.retailer_name, r.id, r.shortname, d.id, d.merchant_id, d.user_id, d.e_updates
OF cc_watchlists d
LEFT JOIN merchant r
ON d.merchant_id = r.id
WHERE d.user_id = #SESSION. Auth.ID #.
ORDER BY r.retailer_name ASC
< / cfquery >
and the exit;
< cfoutput query = "getwatched" >
< TD > < a href = "page.cfm? for = #shortname #" > #retailer_name # < /a > < /dt >
< / cfoutput >
Error States;
coldfusion.runtime.UndefinedVariableException: Variable SHORTNAME is undefined.
I would appreciate any help!Make a
the entire query just before the line which is the slightest error, and
Make sure that it contains what you think that it contains.--
Adam -
That IS NULL is done by replacing the NOT EXISTS operator with an outer join?
DB version: 10 gr 2
An example of searchoracle.target.com
The query that contains a NOT EXISTS operator
is replaced by an equivalent outer join querySELECT M.ModulId, M.Modul FROM MODULE M WHERE NOT EXISTS ( SELECT PROJEKTMODUL.IdModul FROM PROJEKTMODUL WHERE M.ModulId = PROJEKTMODUL.IdModul AND PROJEKTMODUL.IdProjekt = 23 )
I do not understand whatselect distinct M.ModulId , M.Modul from MODULE M left outer join PROJEKTMODUL on M.ModulId = PROJEKTMODUL.IdModul and PROJEKTMODUL.IdProjekt = 23 where PROJEKTMODUL.IdProjekt is null
fact in the above rewritten query.PROJEKTMODUL.IdProjekt is null
He is to perform an anti-jointure. As far as I know Oracle (starting with version 10g - I thought that release 1) rewritten a Join Anti that resembles your second query of your request NOT EXISTS and NOT IN.
Look at the results of the query without the predicate IS NULL and see what records (from this set) must be selected to show the same results as the first query. Areas of interest match the predicate IS NULL.
-
Join query not received from WLC
Hi all
I am in the process of autonomous update 1242 (MIC) APs belongs to an external client to make them a part of the existing lwapp based infrastructure.
I have seen successful negotiations of discovery. Then AP sends the join query, but the WLC debugging does not receive the product.
1. the capture of wireshark packages indicates that Discovery & jOin process use identical to each phased ports: it will be exclude firewalls.
2. no duplicate IPs
3 controllers are not exhausted with APs
4 DHCP option 43 is set up and could see it in action when I do a debug dhcp
Another interesting observation is that I couldn't see any CERT on autonomous before conveting to lwapp APs when I have HS crypto pki certificates
Please refer to the attachment for debugging output.
Any help is very appreciated.
see you soon,
janesha
You open the FW for UDP 12223 and also you have the ip helper and the ip Protocol before?
-
records with an outer join restrictions while using a sub query?
I have the following code:
declare
Default char Activeonly ' n ';
SearchKey varchar2 (15) default '413041494500064';
number of lclAcctNo;
Start
Select
rat_acct_no in lclAcctNo
ACCT,.
marketer_account ma1,
Marketing agent,
Account_Service,
Account_Address
Where (Rat_Acct_No = Mka_Acct_No
and Mka_Exp_Dt = (ma2 select Max (Mka_Exp_Dt) of Marketer_Account
Where Mka_Acct_No = Rat_Acct_No)
and mka_service_type = 'E')
And Rat_Acct_No = Acs_Acct_No
And Rat_Acct_No = Add_Acct_No
"And Add_Address_Type s ="
And Rat_Full_Css_Acct_No as Trim (Searchkey) | '%'
And (Activeonly is Null or Activeonly = ' or (Rat_Acct_Status_Cd = 'A' or Rat_Acct_Status_Cd is Null))
and rownum < 1000;
dbms_output.put_line ('Account' | lclAcctNo);
end;
I'm doing the table MARKETER_ACCOUNT (MKA_fields) an outer join, because the data I expect to will not be on the table, but I want even when the table of ACCT.
I can't do an outer join on subqueries, so wanted to know if there was a way more easy/better to Edifier cela?
I use Oracle 11.2 g.
Thanks for any help.
Sean
Basically, I think, your outer join is ruined by the subquery correlated in the WHERE clause:
R.ToDate = (Select MAX(ToDate) from R r2
Since you joined outside R to A tell you the database to give you the lines of A for which R.ToDate is null * AND * meets your requirement: and this is not possible. Tom Kyte gave the classic explanation for this kind of problem long ago on AskTom: http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4963137609733 ("ask yourself this - how a row in T2 (EMP in your example) the MISSING two (composed due to the outer join) AND have a column that corresponds to something?") It cannot be").
Here's your example in DDL + DML form: ''
create table account)
VARCHAR2 (10) key
, name varchar2 (10)
, status varchar2 (10)
);
insert into account values ('A1', 'John', 'Active');
insert into account values ('A2', 'Mary', 'Active');
insert into account values ('A3', 'James', 'Inactive');
Create array of marketing)
VARCHAR2 (10) key
, Varchar2 (10) Mktr
);
insert into values Marketer ("M1", "ABC");
insert into values Marketer ("M2", "DEF");
create table relationship)
VARCHAR2 (10) key
, Varchar2 (10) AccKey
, MktKey varchar2 (10)
, FromDt varchar2 (10)
, Varchar2 (10) so far
);
insert into the relationship values ('R1', 'A1', 'M1', "" 01/01/2012 ', December 31, 2012 ' ");
insert into the relationship values ('R2', 'A1', 'M2', "01/01/2013 ', 'present'");
insert into the relationship values ('R3', 'A2', 'M2', ' 01 /' 02/2013, 31 / 05/2013 ');
Select B.SID
M.Mktr
R.FromDt
R.ToDate
account A
left join
relationship R
on (a.Key = R.AccKey)
left join
Distributor M
on (R.MktKey = M.Key)
where R.ToDate = (Select MAX (r2. To date)
relationship r2
where r2. AccKey = A.Key)
and A.Status = 'Active '.
;
MKTR FROMDT NAME DATE
---------- ---------- ---------- ----------
Mary DEF 2/1/2013 5/31/2013
John DEF 01/01/2013 presents
-a possibility to obtain all the relevant lines would be to perform filtering after the join:
with
BaseData as)
Select B.SID
A.key
M.Mktr
R.FromDt
R.ToDate
account A
left join
relationship R
on (a.Key = R.AccKey)
left join
Distributor M
on (R.MktKey = M.Key)
)
Select basedata.*
of basedata
where basedata. ToDate = (Select MAX (r2. To date)
relationship r2
where r2. AccKey = basedata. Key)
or basedata. This day is null;
KEY MKTR FROMDT NAME DATE
---------- ---------- ---------- ---------- ----------
Mary A2 DEF 2/1/2013 5/31/2013
John A1 DEF 01/01/2013 presents
James A3
Of course, there are many other possible solutions - since it's SQL...
Concerning
Martin
-
error in the update with a join query
Hi all
IM using oracle 10g on windows.
im not able to use this update query with join...
UPDATE
b
SET
b.is_stud = 1
Of
b Boy
JOIN IN-HOUSE
the relationship r
WE
b.ID = r.boy_id;
Thank you very much...MERGE into emp trg using(Select distinct b.ename ename,a.empno empno from emp a, emp_status b where a.empno=b.empno) src on (trg.empno=src.empno) when matched then update SET trg.name = src.ename;
-
I just installed Firefox 5. Unfortunately, F-Secure "Application Control" now repeatedly appears "Change the Application" messages in an endless chain. It will not accept my attempts to 'Allow' the new version of Firefox. Since Firefox 5 is not compatible with F-Secure, I want to go back to my previous version of Firefox. I am very disappointed that you put me for all this trouble. How can I remove Firefox 5 and revert to the previous version of Firefox?
good new update for firefox 5 was released today
-
1. create a shortcut to a folder.
2. click on the shortcut.
3 explore opens with the contents of the folder in the right pane, but the tree left is not synchronized with the location on the right. You must navigate on the left tree to get to the location of the folder on the right side. In the XP folder as this is done automatically.The whole point (I thought) shortcuts to specific locations in the directory structure was to avoid having to navigate several lower levels from the root of a tree...
Any way to configure the behavior of XP?
Thank you.
Hi Rptrevor,
· How you used to synchronize folders in Windows Explorer?
Follow the steps below to solve the problem:
a. right click on an empty space in the left pane (folder), you get a menu with two options
b. 'show all files' and 'Developing in the current folder'.
c. believing that the empty space is a bit complicated and the options are sticky (it's the same thing than to go through the 'Folder Options' dialog box).
I hope this helps.
-
Writing a query to display data WHERE the data in column do not begin with 'Rep '.
Hello
* (Assuming file_name is a column of table $file_log) *.
Please tell me
How to write a query where I want to display the data for which File_Name does not begin with name like Reports_
Please tell me.
Thank youHello
I hope that this might help
SELECT * FROM FILE_LOG_TABLE WHERE FILE_NAME NOT LIKE 'Reports_%';
see you soon
VT
-
My Ipad mini will not connect with my wifi at home. Other devices are connecting with the wifi at home. I turned the mini ipad market a few times and nothing. He recognizes wifi but when I touch the password, it continues to request the password. Help! It was working fine earlier in the day.
What has happened with your iPad since earlier today, when it worked? updated App or iOS? nothing at all
If your iPhone, iPad or iPod touch connects to a Wi - Fi - Apple Support network
-
Bug with an outer join, or &; Analytics function (or rownum)
Hello
Seems to be a combination of an outer join, OR and rownum confuses the CBO.
First request is without rownum, the second is with rownum.
The second query expects 203 t lines and never ends. It should behave the same as query 1, with 24 M lines.
Remove the GOLD clause query 2 allows him to behave as a query 1, with 24 M lines.
We never saw it? Is there a solution?
SELECT * FROM message i LEFT JOIN (SELECT hi.message_id, hi.update_dt FROM message_hist hi) h ON (t.id = h.master_id AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD'))); ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 24M| 13G| 475G (2)|999:59:59 | | 1 | NESTED LOOPS OUTER | | 24M| 13G| 475G (2)|999:59:59 | | 2 | TABLE ACCESS FULL | MESSAGE | 8037K| 1318M| 29883 (2)| 00:06:59 | | 3 | VIEW | | 3 | 1302 | 59136 (2)| 00:13:48 | |* 4 | TABLE ACCESS FULL| MESSAGE_HIST | 3 | 168 | 59136 (2)| 00:13:48 | ----------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("I"."MESSAGE_ID"="HI"."MESSAGE_ID" AND ("HI"."UPDATE_DT"<TO_DATE('150901','RRMMDD') OR "I"."UPDATE_DT"="HI"."UPDATE_DT")) ---------------- SELECT * FROM message i LEFT JOIN (SELECT hi.message_id, hi.update_dt , ROWNUM FROM message_hist hi) h ON (t.id = h.master_id AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD'))); ------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 203T| 112P| 475G (2)|999:59:59 | | 1 | NESTED LOOPS OUTER | | 203T| 112P| 475G (2)|999:59:59 | | 2 | TABLE ACCESS FULL | MESSAGE | 8037K| 1318M| 29883 (2)| 00:06:59 | | 3 | VIEW | | 25M| 10G| 59151 (2)| 00:13:49 | |* 4 | VIEW | | 25M| 10G| 59151 (2)| 00:13:49 | | 5 | COUNT | | | | | | | 6 | TABLE ACCESS FULL| MESSAGE_HIST | 25M| 1355M| 59151 (2)| 00:13:49 | ------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("I"."MESSAGE_ID"="H"."MESSAGE_ID" AND ("I"."UPDATE_DT"="H"."UPDATE_DT" OR "H"."UPDATE_DT"<TO_DATE('150901','RRMMDD')))
RowNum in a subquery is supposed to ensure that the subquery is evaluated completely before filtering, otherwise, how could you go out rownum?
Your question is compounded because of the join condition that forces a level of nested loops, which means that the table should be fully analysed once for each line of conduct rowsource. You can either transform the join in an equijoin and allow a hash to run, or you join could materialize the subquery once.
Allow the hash join:
SELECT count (*)
Message FROM
LEFT JOIN (SELECT hi.message_id, hi.update_dt
ROWNUM
OF message_hist salvation) PM ON (i.message_id = h.message_id
AND i.update_dt = h.update_dt)
LEFT JOIN (SELECT hi.message_id, hi.update_dt
ROWNUM
OF message_hist salvation) h2 ON (i.message_id = h2.message_id
AND h2.update_dt<>
AND h2.update_dt <> i.update_dt)
/
----------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 66. 211 (1) | 00:00:01 |
| 1. GLOBAL TRI | | 1. 66. | |
|* 2 | EXTERNAL RIGHT HASH JOIN | | 800 | 52800 | 211 (1) | 00:00:01 |
|* 3 | VIEW | | 1. 22. 70 (0) | 00:00:01 |
| 4. COUNTY | | | | | |
| 5. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
|* 6 | EXTERNAL RIGHT HASH JOIN | | 800 | 35200. 141 (1) | 00:00:01 |
| 7. VIEW | | 1. 22. 70 (0) | 00:00:01 |
| 8. COUNTY | | | | | |
| 9. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | MESSAGE | 800 | 17600 | 70 (0) | 00:00:01 |
----------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
2 - access("I".") MESSAGE_ID '= 'H2'.' MESSAGE_ID "(+))"
filter ("H2". "UPDATE_DT" (+)<>'I'. " ("' UPDATE_DT")
3 - filter("H2".") UPDATE_DT "(+)<>
6 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND"
"I"." ' MESSAGE_ID ' ="H" MESSAGE_ID "(+))"
Materialize the subquery:
WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)
ROWNUM
OF message_hist salvation)
SELECT count (*)
Message FROM
LEFT JOIN: ON (i.message_id = h.message_id
AND (i.update_dt = h.update_dt OR h.update_dt<>
----------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 22. 1740 (0) | 00:00:01 |
| 1. TRANSFORMATION OF THE TEMPORARY TABLE. | | | | |
| 2. LOAD SELECT ACE | SYS_TEMP_0FD9D6810_5B8F6E67 | | | | |
| 3. COUNT | | | | | |
| 4. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
| 5. GLOBAL TRI | | 1. 22. | |
| 6. NESTED EXTERNAL LOOPS | | 800 | 17600 | 1670 (0) | 00:00:01 |
| 7. TABLE ACCESS FULL | MESSAGE | 800 | 17600 | 70 (0) | 00:00:01 |
| 8. VIEW | | 1. | 2 (0) | 00:00:01 |
|* 9 | VIEW | | 1. 22. 2 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | SYS_TEMP_0FD9D6810_5B8F6E67 | 1. 22. 2 (0) | 00:00:01 |
----------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
9 - filter("I".") ' MESSAGE_ID ' ="H" MESSAGE_ID' AND ('I'. "" "UPDATE_DT"="H" UPDATE_DT' OR
"H"." UPDATE_DT ".<>
You may need to change the first condition to make sure that you select the correct subquery.
-edit
Not able to view a plan but you can invade the second join condition select and then the result of a subquery with a predicate according to your requirement. This should delay the or rating and leave only an equijoin (although rowsource return may be slightly larger than the opposite).
-Second edition, it did not work exactly when I tried it.
A hybrid of the previous two plans with a slight modification of how he was imitating the GOLD:
WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)
ROWNUM Clotilde
OF message_hist salvation)
SELECT i.MESSAGE_ID
i.UPDATE_DT
COALESCE(h.message_id,h2.message_id) message_id
, COALESCE (h.update_dt, h2.update_dt) update_dt
Clotilde COALESCE (h.rown, h2.rown)
Message FROM
LEFT JOIN: ON (i.message_id = h.message_id
AND i.update_dt = h.update_dt)
LEFT JOIN: h2 WE (DECODE(h.message_id,,i.message_id) = h2.message_id - only try this if previous join returned NULL
AND h2.update_dt<>
/
--------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 66. 8 (0) | 00:00:01 |
| 1. TRANSFORMATION OF THE TEMPORARY TABLE. | | | | |
| 2. LOAD SELECT ACE | SYS_TEMP_0FD9D6605_28F27F | | | | |
| 3. COUNT | | | | | |
| 4. TABLE ACCESS FULL | MESSAGE_HIST | 150. 3300 | 2 (0) | 00:00:01 |
| 5. GLOBAL TRI | | 1. 66. | |
|* 6 | EXTERNAL RIGHT HASH JOIN | | 10497. 676K | 6 (0). 00:00:01 |
|* 7 | VIEW | | 150. 3300 | 2 (0) | 00:00:01 |
| 8. TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F | 150. 3300 | 2 (0) | 00:00:01 |
|* 9 | OUTER HASH JOIN | | 328. 14432 | 4 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | MESSAGE | 200 | 4400 | 2 (0) | 00:00:01 |
| 11. VIEW | | 150. 3300 | 2 (0) | 00:00:01 |
| 12. TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F | 150. 3300 | 2 (0) | 00:00:01 |
--------------------------------------------------------------------------------------------------------Information of predicates (identified by the operation identity card):
---------------------------------------------------6 - access("H2".") MESSAGE_ID "(+) = DECODE (TO_CHAR ('H'". "))" MESSAGE_ID"), NULL, 'I '. (("' MESSAGE_ID '))
7 - filter("H2".") UPDATE_DT "(+)<>
9 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND 'I'." "" ' MESSAGE_ID '="H" MESSAGE_ID "(+))"(This plan is another system if costs are not comparable)
Maybe you are looking for
-
MaskMe breeze Web sites, what can I do?
Some sites Web is broken (DuckDuckGo.com, NASA, Cult Of Mac, Twitter, Google +) when I have a plugin called MaskMe. He remembers passwords and gives sites of disposable emails to stop the spam. It does nothing else, but can someone tell me why the Ma
-
You have my T430s Question on screen
Hello I got my T430s for 10 days now and I am very happy with the machine, with the exception of the screen, which is manufactured by Samsung. When I have an all white screen, the bottom of it shows a white relatively well, while the top shows a gray
-
Data transfer Ethernet fails on deployed Application RT
I wrote a TCP/IP client that interacts with a TCP/IP server on a LAN (cable). I've developed this during a few months on LabVIEW 2014 (no SP1) targeting a cRIO9068 chassis. Development went very well, never had any problem Ethernet flaky with LabVIEW
-
Arduino to control with labview
HelloI want to use my arduino uno with Labview, I just need the arduino to send pulses of 5 volts X dry all the secondsHow can I do through labview? Thank you
-
Email & save the spreadsheet in pdf format based on cell references
I'm using Mail_Every_Worksheet_With_Address_In_A1_PDF of Ron as an example and I would like to save and name the PDF to a folder using cells Ref: A2_Client name with a suffix of the name of the journal. For example: my documents/Clients ABC Company l