Join in a query
Hello!
I'm neawby in SQL, and I have some problems with a query...
I have a table called "Artist" like this:
ART_ID ART_NAME ART_DESCRIPTION
1 Artist1 Desc1
2 Artist2 Desc2
3 Artist3 Desc3
4 Artist4 Desc4And another table called "Tour" like this:
TOUR_ID TOUR_DATE TOUR_ART_ID
1 10/10/2013 1
2 14/07/2014 4And definitively, I want to show something like this:
ART_ID ART_NAME ART_DESCRIPTION TOUR_DATE
1 Artist1 Desc1 10/10/2013
2 Artist2 Desc2
3 Artist3 Desc3
4 Artist4 Desc4 14/07/2014If no tour_date for this artist, I want to show the artist too.
Thanks in advance!
John Stegeman wrote:
Marccccc,
Let me give you a hint to see if it will help you. Try it out, and if you cannot get it, come back and tell us what you tried
Hint: outer joins.
Edit: Blu ruined my nifty little idea :)Apologies John. I was in a kind mood as the OP at least bothered to display his data using {noformat}{noformat} tags so we could read it, and made it clear what he wanted, unlike some of the "I've got this... +unformatted data+ and I want this... +unformatted output+" questions we get. ;)
Similar Messages
-
Restriction to Left Outer Joins in PS Query
Hello I am trying to do Left Outer JOin in PS QUERY. I need to do dept tbl, job code tbl and locatable as left outer joins with JOB Table. Looks like in PS QUERY there is a error message saying as below. Can someone has any workaround to achieve this in PS QUERY. I know I can create a View and use that in PS QUERY but BUsiness Users are dependent on IT, so that doesn't work. Also, adding JOB table multiple times works but I am looking for better solution if anyone had come accorss working through PS QUERY Outer JOins.
Windows Internet Explorer
Left outer joins must be joined to the last record in the query. (139,290)
OK
Thanks,
SC.Hi Mike,
According to your description, you want to improve the performance for your DAX query in SQL Server Analysis Service Tabular model, right? Here is a white paper describes strategies and specific techniques for getting the best performance from your tabular
models, including processing and partitioning strategies, DAX query tuning, and server tuning for specific workloads.
http://msdn.microsoft.com/en-us/library/dn393915.aspx
Since this is a complex DAX query, from a support perspective this is really beyond what we can do here in the forums. If you cannot determine your answer here or on your own, consider opening a support case with Microsoft. Visit this link to see the various
support options that are available to better meet your needs:
http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
Regards,
Charlie Liao
TechNet Community Support -
How to make outer join in Sub Query?
Hi!
I'm facing one problem. Can anyone tell me - how to make outer join in sub query?
I'm pasting one sample code -
select e.empno, e.ename,e.job,e.sal,d.deptno,d.dname
from d_emp e, d_dept d
where e.deptno(+) = (
case
when d_dept.deptno = 10
then
select deptno
from d_dept
where dname = 'SALES'
else
d_dept.deptno
end
SQL>
ERROR at line 15:
ORA-01799: a column may not be outer-joined to a subqueryHow to resolve this issue?
Regards.And any luck with this?
SQL> with emp as
2 (select 100 empno, 'Abcd' ename, 1000 sal, 10 deptno from dual
3 union all
4 select 101 empno, 'RRR' ename, 2000 sal, 20 deptno from dual
5 union all
6 select 102 empno, 'KKK' ename, 3000 sal, 30 deptno from dual
7 union all
8 select 103 empno, 'PPP' ename, 4000 sal, 10 deptno from dual
9 )
10 ,dept as
11 (select 10 deptno, 'FINANCE' dname from dual
12 union all
13 select 20 deptno, 'SALES' dname from dual
14 union all
15 select 30 deptno, 'IT' dname from dual
16 union all
17 select 40 deptno, 'HR' dname from dual
18 )
19 select e.empno, e.ename, e.sal, d.deptno, d.dname
20 from emp e,
21 (select decode(a.deptno, 10, b.deptno, a.deptno) deptno, decode(a.deptno, 10, b.dname, a.dname) dname
22 from dept a, (select deptno, dname
23 from dept
24 where dname = 'SALES'
25 ) b
26 ) d
27 where e.deptno(+) = d.deptno
28 /
EMPNO ENAM SAL DEPTNO DNAME
101 RRR 2000 20 SALES
101 RRR 2000 20 SALES
102 KKK 3000 30 IT
40 HR
SQL> Cheers
Sarma. -
Joining with sub query not working
Hi
I am new with these complex queries. I am trying to join a sub query to a query as below;
SELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo, (SELECT EventID, SUM(Total) FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) AS Total
FROM tblEvents AS Events1 LEFT OUTER JOIN
tblClients ON Events1.ClientID = tblClients.ID
WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate
HAVING (Events1.InvoiceBatch = 5212)
ORDER BY tblClients.Company
I am getting these two errors;
Msg 8120, Level 16, State 1, Line 2
Column 'tblEvents.ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 116, Level 16, State 1, Line 2
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
What am I missing?
Thanks
RegardsSELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo,Total
FROM tblEvents AS Events1 LEFT OUTER JOIN
tblClients ON Events1.ClientID = tblClients.ID
LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
ON sb.EventID = Events1.ID
WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate,Total
HAVING (Events1.InvoiceBatch = 5212)
ORDER BY tblClients.Company
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page
Says;
Msg 4104, Level 16, State 1, Line 5
The multi-part identifier "Events1.ID" could not be bound.
on
LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
Regards -
I have written the below query, our requirement is, Some employees have "Transport Allowance" but not "Project Allowance". For this, I tried to use OUTER JOIN with this query. But this query takes long time and failed. The following query works fine if the employee has both "Transport Allowance" and "Project Allowance" (without outer join) Now, I also need to retrieve the employees who have "Transport Allowance" but not "Project Allowance". How can I retrieve it?
SELECT DISTINCT papf.employee_number
, peev.screen_entry_value Transport_Allowance
,peev1.screen_entry_value Project_Allowance
FROM apps.per_all_people_f papf
,apps.per_all_assignments_f paaf
,apps.pay_element_types_x petf
,apps.pay_element_types_x petf1
,apps.pay_element_types_x petf2
,apps.pay_element_entries_f peef
,apps.pay_element_entries_f peef1
,apps.pay_element_entries_f peef2
,apps.pay_element_entry_values_x peev
,apps.pay_element_entry_values_x peev1
,apps.pay_element_entry_values_x peev2
,apps.pay_input_values_x pivf
,apps.pay_input_values_x pivf1
,apps.pay_input_values_x pivf2
WHERE
papf.person_id = paaf.person_id
AND paaf.assignment_id = peef.assignment_id
AND paaf.assignment_id = peef1.assignment_id
AND paaf.business_group_id = papf.business_group_id
--Transport Allowance
AND peef.element_entry_id = peev.element_entry_id
AND petf.element_Name = 'Transport Allowance'
AND pivf.element_type_id =petf.element_type_id
AND pivf.name = 'Allowance'
AND peev.input_value_id= pivf.input_value_id
--Project Allowance
AND peef1.element_entry_id = peev1.element_entry_id
AND petf1.element_Name = "Project Allowance'
AND pivf1.element_type_id = petf1.element_type_id
AND pivf1.name = 'Allowance'
AND peev1.input_value_id = pivf1.input_value_id
AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
ORDER BY papf.employee_number
Thanks in advance.I am using sames tables with alias to retrieve the columns values from the same table.
Here is my query.
SELECT DISTINCT papf.employee_number
, peev.screen_entry_value Transport_Allowance
,peev1.screen_entry_value Project_Allowance
FROM apps.per_all_people_f papf
,apps.per_all_assignments_f paaf
,apps.pay_element_types_x petf
,apps.pay_element_types_x petf1
,apps.pay_element_entries_f peef
,apps.pay_element_entries_f peef1
,apps.pay_element_entry_values_x peev
,apps.pay_element_entry_values_x peev1
,apps.pay_input_values_x pivf
,apps.pay_input_values_x pivf1
WHERE
papf.person_id = paaf.person_id
AND paaf.assignment_id = peef.assignment_id
AND paaf.assignment_id = peef1.assignment_id
AND paaf.business_group_id = papf.business_group_id
--Transport Allowance
AND peef.element_entry_id = peev.element_entry_id
AND petf.element_Name = 'Transport Allowance'
AND pivf.element_type_id =petf.element_type_id
AND pivf.name = 'Allowance'
AND peev.input_value_id= pivf.input_value_id
--Project Allowance
AND peef1.element_entry_id = peev1.element_entry_id
AND petf1.element_Name = "Project Allowance'
AND pivf1.element_type_id = petf1.element_type_id
AND pivf1.name = 'Allowance'
AND peev1.input_value_id = pivf1.input_value_id
AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
ORDER BY papf.employee_number
Thanks in advance. -
Hello all,
How to create a self join using ABAP Query?
Say, I have this table EKBE with belnr (materials doc num) and lfbnr (reference material doc num). I have to pick the PO's from EKBE whose belnr doesnt have any lfbnr.
Regards
Madhumathi Ahi madhu,
tables : ekbe.
data itab like standard table of ekbe with header line.
select * from ekbe into table itab where belnr >< 0 and lfbnr = ' '.
loop at itab.
write :/ itab-belnr,itab-lfbnr.
endloop.
check this code this works to select the orders whose belnr doesnt have any lfbnr
reward points if useful. -
Dear Sir/Madam
I'm a student who is interested in Oracle Database and
I have some problems with JOIN and Sub-query.
I hope so many of you could help me.
if i use JOIN without sub-query, may it be faster or not?
SELECT field1, field2 FROM tableA INNER JOIN tableB
if i use JOIN with sub-query, may it be faster or not?
SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
Thanks in advance!Hi,
fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
Dear Sir/Madam
I'm a student who is interested in Oracle Database and
I have some problems with JOIN and Sub-query.
I hope so many of you could help me.
if i use JOIN without sub-query, may it be faster or not?
SELECT field1, field2 FROM tableA INNER JOIN tableB
if i use JOIN with sub-query, may it be faster or not?
SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
Thanks in advance!
As the others have said, the execution plan will give you a better idea about which is faster.
If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible. For example, include field3 in both queries, or ignore field3 in both queries.
In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess. I can't see your execution plans.
In general, simpler code is faster, and better in other ways, too. In this case
tableB
is simpler than
(SELECT field1, field2 FROM tableB)
Why do you want a sub-query in this example? -
Hi All
Following query is to monitor users tablespace and temp tablesapce. How do I can join these two query as a single query. Kindly assist.
Users tablespace mon:
==============
select TT.tablespace_name,
round(TOTAL) TOTAL,
round(FREE) FREE,
round(TOTAL - FREE) USED,
round(100*(TOTAL - FREE)/TOTAL) PCT_USED
from
(select tablespace_name, sum(bytes)/1024/1024 FREE
from dba_free_space group by tablespace_name) FR,
(select tablespace_name, sum(bytes)/1024/1024 TOTAL
from dba_data_files group by tablespace_name) TT
where TT.tablespace_name = FR.tablespace_name(+);
Temp tablespace mon:
===============
select TT.tablespace_name,
round(TOTAL) TOTAL,
round(FREE) FREE,
round(TOTAL - FREE) USED,
round(100*(TOTAL - FREE)/TOTAL) PCT_USED
from
(select tablespace_name, sum(bytes_free)/1024/1024 FREE
from v$temp_space_header group by tablespace_name) FR,
(select tablespace_name, sum(bytes)/1024/1024 TOTAL
from dba_temp_files group by tablespace_name) TT
where TT.tablespace_name = FR.tablespace_name(+);select TT.tablespace_name,
round(TOTAL) TOTAL,
round(FREE) FREE,
round(TOTAL - FREE) USED,
round(100*(TOTAL - FREE)/TOTAL) PCT_USED
from
(select tablespace_name, sum(bytes)/1024/1024 FREE
from dba_free_space group by tablespace_name) FR,
(select tablespace_name, sum(bytes)/1024/1024 TOTAL
from dba_data_files group by tablespace_name) TT
where TT.tablespace_name = FR.tablespace_name(+)
UNION
select TT.tablespace_name,
round(TOTAL) TOTAL,
round(FREE) FREE,
round(TOTAL - FREE) USED,
round(100*(TOTAL - FREE)/TOTAL) PCT_USED
from
(select tablespace_name, sum(bytes_free)/1024/1024 FREE
from v$temp_space_header group by tablespace_name) FR,
(select tablespace_name, sum(bytes)/1024/1024 TOTAL
from dba_temp_files group by tablespace_name) TT
where TT.tablespace_name = FR.tablespace_name(+); -
Problem with JOINs in SELECT query
The parameter wa_dob-e_dob is not getting its definition ....
it contains DOB in current yr.
As i am using Joins also Workarea.... so is it coz Joins & WA cant be used simultaneously in a SELECT query....
Is there any other option to do the same...?
* Global Structure
TYPES : BEGIN OF t_data , "Structure
emp_dob TYPE pa0002-gbdat,
emp_Mailid TYPE pa0105-usrid,
END OF t_data,
BEGIN OF t_dob,
e_dob TYPE pa0002-gbdat,
e_pernr type pa0002-pernr,
END OF t_dob.
* Global Internal Tables (I_)
DATA : i_data TYPE TABLE OF t_data, "Internal Table for output data
i_dob TYPE TABLE OF t_dob. "Internal table for Dob
* Global Work Area (WA_)
DATA : wa_data TYPE t_data, "Work Area for output data
wa_dob TYPE t_dob. "Work Area for Dob
*this is the query where i am getting error
* Field "WA_DOB-E_DOB" Not found.
LOOP AT i_dob INTO wa_dob.
SELECT pa0002~gbdat pa0105~usrid INTO CORRESPONDING FIELDS OF wa_data
FROM pa0002
INNER JOIN pa0105
ON pa0002~pernr = pa0105~pernr
WHERE pa0105~subty EQ 'MAIL' AND
wa_dob-e_dob BETWEEN w_sysdate AND w_edit_sysdate.
ENDSELECT.
APPEND wa_data TO i_data.
CLEAR wa_data.
CLEAR wa_dob.
CLEAR l_temp_dob.
ENDLOOP.Hi,
you are checking the work area in the SELECT. IN WHERE condition of the select u should specify fields in either of the tables pa0002 , pa0105 for data population.
The select is on the database table and not on the work area.for checking the data in the work area do this way:
loop at it_dob into wa_dob.
if wa_dob-e_dob between the range u want (w_sysdate AND w_edit_sysdate)
endif.
endloop.
ie: wa_dob-e_dob >w_sysdate AND wa_dob-e_dob < w_edit_sysdate or
wa_dob-e_dob < w_sysdate AND wa_dob-e_dob > w_edit_sysdate
watever ur requirement is..
regards,
madhu -
Hi,
I'm trying to execute some SQL queries and I just don't understand what's wrong.
I�m using Tomcat and SQL Server in order to do this, but when I�m try to execute a query with a INNER JOIN statements Tomcat raise a SQL exception... at the very first time I thought there was a problem with database connection but I realize that a simple query to a table works pretty well. then I found out some problems with JDBC:ODBC.... so I install JDBC for SQL Server 2000 and test with the same simple query and works..... so, I come to a conclusion.... INNER JOIN or JOIN statements can't be used in JDBC..... please... somebody tell I�m wrong and give me a hand...
I'm using TOMCAT 4 and JDK 1.4 SQL Server 2000
Error occurs when executeQuery() is called.... not prepareStatement().... ??????
Driver DriverRecResult = (Driver)Class.forName(driver).newInstance();
Connection ConnRecResult = DriverManager.getConnection(DSN,user,password);
PreparedStatement StatementRecResult = ConnRecResult.prepareStatement(query);
ResultSet RecResult = StatementRecResult.executeQuery(); <---- Exception raise here
So much tahnks in advance,That's exactly what I think, driver it's raising the exception, but I don't know why.... i test the same query with INNER JOIN directly from SQL Query Analyser and it's works perfectly, my problem ain't SQL, but JSP and JDBC 'cause i'm a newbie about these issues.
Common sense tell me possible problems lie in SQLServer drivers 'cause i run the same pages on JRUN through jdbc:odbc and do works well, but by now i just depend on Tomcat.....
I've installed SQL Server drivers for JDBC but i just find it doesn't work fully... could be the version of JDK i've installed? what version do i need?
( I'm running Tomcat 4 with JDK 1.4 & SQL Server 2000 W2K )
thanks for reply. -
How to use outer join on this query?
Hi all,
Hope doing well,
sir i am having one query which is here
SELECT C.* ,
P.Comp_Name Parent
FROM Comp_Master C
LEFT JOIN Comp_Master P
ON C.Parent_ID = P.Comp_ID
WHERE C.Comp_ID = 5;
and here is my table Comp_Master data like this:
Comp_ID Parent_ID Comp_Name
5 1 abc123
1 ROOT abc@123
after running this query with all column value in parent column abc@123 value should come. but it's not happening.
could u check this.
if any query please let me know.
Thanksp.s. when I run your query against your data....
SQL> ed
Wrote file afiedt.buf
1 with comp_master as (select '5' comp_id, '1' parent_id, 'abc123' comp_name from dual union all
2 select '1' comp_id, 'ROOT' parent_id, 'abc@123' comp_name from dual
3 )
4 --
5 -- end of simulated table of test data
6 --
7 SELECT C.*
8 ,P.Comp_Name Parent
9 FROM Comp_Master C
10 LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID
11* WHERE C.Comp_ID = 5
SQL> /
C PARE COMP_NA PARENT
5 1 abc123 abc@123I get the output I expect from that query.
So what are you expecting?
I just ran the equivalent in SQL Server (I can't believe you got me to go and run that piece of rubbish... I haven't touched it in ages)...
with comp_master as (select '5' comp_id, '1' parent_id, 'abc123' comp_name union all
select '1' comp_id, 'ROOT' parent_id, 'abc@123' comp_name
SELECT C.*
,P.Comp_Name Parent
FROM Comp_Master C
LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID
WHERE C.Comp_ID = 5... and it gave me the same output. -
Joins issue in query - OBIEE 11g
Hi all,
I have created a new repository with a simple star schema, and also have created ragged hierarchy. Now when i select any dimension field and a measure from the fact, the query generated by BI has 2 physical queries i.e. one for dimension and other for fact. but when it joins these 2 subqueries it does not consider any common column to join on , and results in incorrect data.
Not able to figure out what is going wrong. Pls. let me know hw to resolve this issue if any one has faced a similar one.
rgds,
ShrutiRqList <<184070>> [for database 3023:147018:DEVFRC,57] /* FETCH FIRST 1000001 ROWS ONLY */
0 as c1 [for database 3023:147018,57],
D2.c1 as c2 [for database 3023:147018,57],
D1.c1 as c3 [for database 3023:147018,57]
Child Nodes (RqJoinSpec): <<184109>> [for database 3023:147018:DEVFRC,57]
RqJoinNode <<184107>> []
RqList <<184082>> [for database 3023:147018:DEVFRC,57] distinct
sum(FCT_LEDGER_STAT.N_VALUE) as c1 [for database 3023:147018,57]
Child Nodes (RqJoinSpec): <<184085>> [for database 3023:147018:DEVFRC,57]
RqJoinNode <<184084>> []
FCT_LEDGER_STAT T147426
) as D1
RqJoinNode <<184108>> []
RqList <<184088>> [for database 3023:147018:DEVFRC,57] distinct
DIM_FINANCIAL_ELEMENT.V_FINANCIAL_ELEM_NAME as c1 [for database 3023:147018,57]
Child Nodes (RqJoinSpec): <<184099>> [for database 3023:147018:DEVFRC,57]
RqJoinNode <<184098>> []
DIM_FINANCIAL_ELEMENT T147109
) as D2
OrderBy: c2 asc NULLS LAST [for database 3023:147018,57]
=========================================================
PHYSICAL
==================================================
WITH
SAWITH0 AS (select sum(T147426.N_VALUE) as c1
from
OFSAAATOMIC.FCT_LEDGER_STAT T147426),
SAWITH1 AS (select distinct T147109.V_FINANCIAL_ELEM_NAME as c1
from
OFSAAATOMIC.DIM_FINANCIAL_ELEMENT T147109)
select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3 from ( select 0 as c1,
D2.c1 as c2,
D1.c1 as c3
from
SAWITH0 D1,
SAWITH1 D2
order by c2 ) D1 where rownum <= 1000001 -
Hi All,
I need to do an enhancement in the following Select query.
SELECT
MARA data
a~matnr
MARC data
b~werks
MARA data
a~normt
a~ean11
a~labor
a~mstae
a~mstde
a~bismt
a~spart
a~zzsc
a~zzmc
a~zzpc
a~zzbu
a~zz4tpc
a~zz6tpc
a~kosch
a~iprkz
g~bmatn
a~normt
g~mfrnr
a~bstme
a~zeifo
a~ersda
MARC data
b~mtvfp
b~sernp
b~herkl
b~ekgrp
b~dispo
b~insmk
b~disgr
b~ladgr
b~lgfsb
b~mtver
b~perkz
b~eprio
b~wzeit
MVKE data
c~dwerk
c~kondm
c~bonus
c~mtpos
c~provg
c~mvgr1
c~mvgr2
c~mvgr3
c~prat9
c~prat1
MBEW data
d~bklas
d~stprs
INTO TABLE i_materials
FROM ( marc as b
inner jOIN mara AS a ON amatnr = bmatnr
inner JOIN mvke AS c ON cmatnr = amatnr
inner JOIN ampl AS g ON gbmatn = amatnr
LEFT OUTER JOIN mbew AS d ON dmatnr = bmatnr
AND dbwkey = bwerks )
WHERE a~matnr IN s_matnr
AND a~normt IN s_normt
AND a~mstae IN s_mstae
AND a~zz4tpc IN s_zz4tpc
AND a~zz6tpc IN s_zz6tpc
AND a~bismt IN s_bismt
AND a~iprkz IN s_iprkz
AND a~spart IN s_spart
AND a~zzsc IN s_zzsc
AND a~zzpc IN s_zzpc
AND a~zzmc IN s_zzmc
AND a~zzbu IN s_zzbu
AND a~ersda IN s_ersda
MARC Data
AND b~werks IN s_werks
AND b~ekgrp IN s_ekgrp
AND b~disgr IN s_disgr
AND b~perkz IN s_perkz
AND b~sernp IN s_sernp
AND b~ladgr IN s_ladgr
AND b~mtvfp IN s_mtvfp
AND b~lgfsb IN s_lgfsb
AND b~mtver IN s_mtver
AND b~eprio IN s_eprio
AND b~wzeit IN s_wzeit
AND b~herkl IN s_herkl
MVKE data
AND c~mtpos IN s_mtpos
AND c~kondm IN s_kondm
AND c~bonus IN s_bonus
AND c~provg IN s_provg
AND c~mvgr1 IN s_mvgr1
AND c~mvgr2 IN s_mvgr2
AND c~mvgr3 IN s_mvgr3
AMPL Data
AND g~reoam <> 'X'.
This query will pick the materials only if it is maintained across all the tables MARA,MARC,MVKE,AMPL,MBEW.
Now the requirement is, the program should pick the materials that are maintained in MARA table, doesn't matter if the material is not maintained in the other tables.
Please tell me how to modify this Select query. I dont have any idea on JOINs.
Thanks in Advance,
Neethu.Hi Manoj,
I have modified the query like
select fields
FROM ( mara as a
left outer join marc AS b ON amatnr = bmatnr
left outer Join mvke AS c ON amatnr = cmatnr
left outer Join ampl AS g ON amatnr = gbmatn
left outer Join mbew AS d ON amatnr = dmatnr )
WHERE a~matnr IN s_matnr
AND a~normt IN s_normt
AND a~mstae IN s_mstae
AND a~zz4tpc IN s_zz4tpc
AND a~zz6tpc IN s_zz6tpc
AND a~bismt IN s_bismt
AND a~iprkz IN s_iprkz
AND a~spart IN s_spart
AND a~zzsc IN s_zzsc
AND a~zzpc IN s_zzpc
AND a~zzmc IN s_zzmc
AND a~zzbu IN s_zzbu
AND a~ersda IN s_ersda
MARC Data
AND b~werks IN s_werks
AND b~ekgrp IN s_ekgrp
AND b~disgr IN s_disgr
AND b~perkz IN s_perkz
AND b~sernp IN s_sernp
AND b~ladgr IN s_ladgr
AND b~mtvfp IN s_mtvfp
AND b~lgfsb IN s_lgfsb
AND b~mtver IN s_mtver
AND b~eprio IN s_eprio
AND b~wzeit IN s_wzeit
AND b~herkl IN s_herkl
MVKE data
AND c~mtpos IN s_mtpos
AND c~kondm IN s_kondm
AND c~bonus IN s_bonus
AND c~provg IN s_provg
AND c~mvgr1 IN s_mvgr1
AND c~mvgr2 IN s_mvgr2
AND c~mvgr3 IN s_mvgr3
AMPL Data
AND g~reoam <> 'X'.
I am getting the error, "No fields from the right-hand table of a LEFT OUTER JOIN may appear in the WHERE condition:"B~WERKS".
Now prob. is with WHERE condition. If you know the solution please let me know. -
Could anyone help me to avoid Cartesian join in this query?
Hi, guys:
Could you help me on this query? I must generate a Cartesian join, but I do not know why it happens. dt.debtorkey, cl.clientkey, inv.invoicekey, ag.agingkey are primary keys of each table. The problem is: I got same tuple for 8 times.
select dt.debtorkey, cl.clientkey, inv.invoicekey, ag.agingkey, dt.DebtorNo, dt.Name as "debtor Name", dt.State, cl.ClientNo, cl.Name as "Client Name", inv.InvNo, inv.PurchOrd, inv.Amt,
to_char(inv.InvDate, 'MM-DD-YY') invoice_date, to_char(ag.DateLastBuy, 'MM-DD-YY') aging_lastbuy, to_char(ag.DateLastPmt, 'MM-DD-YY') aging_lastpmt
from aging ag, invoices inv, debtors dt, clients cl
where ag.clientkey=cl.clientkey
and ag.debtorkey=dt.debtorkey
and inv.clientkey=cl.clientkey
and inv.debtorkey=dt.debtorkey
and ((inv.InvDate>=to_date(:P16_DP_IDF_START_DATE, 'MM/DD/YYYY')
and inv.InvDate<=to_date(:P16_DP_IDF_END_DATE, 'MM/DD/YYYY')
and ag.DateLastBuy=to_date(:P16_DP_IDF_LAST_BUY,'MM/DD/YYYY')
order by dt.name;Thanks a lot!Hi,
Thanks for help. I am sorry for that I do not know how to upload a picture of explain plan. I am struggling to find how to provide sample data. I hope this data format could be at least useful.
"DEBTORKEY","CLIENTKEY","INVOICEKEY","AGINGKEY","DEBTORNO","debtor Name","STATE","CLIENTNO","Client Name","INVNO","PURCHORD","AMT","INVOICE_DATE"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"I do not know why the tuples with same primary key repeat 8 times.
Edited by: lxiscas on Oct 24, 2012 4:08 PM
Edited by: lxiscas on Oct 24, 2012 4:10 PM -
No join in the query involving 2 tables
Friends,
I saw a strange plan for one query in TESTING DB today. Although 2 tables are involved i dont see any join , NL/HJ/SMJ !!
Can you please tell why this might be happening?
Note: i am not facing any performance issue but curious to know what type of optimization oracle is doing here.
It would be great if you could direct me the relevant link in the documentation.
Query text and plan :
SELECT FIRST_NAME
FROM CAMPA.TABLE_A
WHERE NAME_ID =
(SELECT NAME_ID
FROM CAMPA.TABLE_B
WHERE ban=:b1);
Plan hash value: 311916800
| Id | Operation | Name | Rows | Bytes | Cost | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 12 | 2 | | |
| 1 | PARTITION RANGE SINGLE | | 1 | 12 | 1 | KEY | KEY |
| 2 | TABLE ACCESS BY LOCAL INDEX ROWID | TABLE_A | 1 | 12 | 1 | KEY | KEY |
|* 3 | INDEX UNIQUE SCAN | TABLE_A_PK | 1 | | 1 | KEY | KEY |
| 4 | PARTITION RANGE SINGLE | | 2 | 30 | 1 | KEY | KEY |
| 5 | TABLE ACCESS BY LOCAL INDEX ROWID| TABLE_B | 2 | 30 | 1 | KEY | KEY |
|* 6 | INDEX RANGE SCAN | TABLE_B_2IX | 2 | | 1 | KEY | KEY |
Predicate Information (identified by operation id):
3 - access("NAME_ID"= (SELECT "NAME_ID" FROM "CAMPA"."TABLE_B" "TABLE_B"
WHERE "BAN"=TO_NUMBER(:B1)))
6 - access("BAN"=TO_NUMBER(:B1))
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for HPUX: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionWith equality condition can i get NL/HJ join where the outer row source comes from the subquery?
What condition/pre-requisite of NL/HJ join is not met in this case?Don't use an equality condition with a subquery - this implicitly makes available to the CBO an optimisation strategy that can only be used if the subquery is guaranteed to return a single row.
So either use IN rather than = or use a JOIN not a SUBQUERY.
It's a bit of a strange question.
How do I remove this optimisation?
Take away the features that make that optimisation a possibility.
Edited by: Dom Brooks on May 13, 2013 2:20 PM
Maybe you are looking for
-
Please help...any ideas? scroll pad and the letter 's'
the scroll pad isnt scrolling around the main menu nor is the letter 's' working at all...you know how many words use the letter 's'??? anyways, any ideas what i should do? i done a battery pull, resetting the phone, updating it.....so help? please?
-
How to email a flash animation
I am trying to email a flash animation to our sales force. I cannot seem to make this work. The only way that works is making it an animated gif. However, when I do this, it looks more like an illustration and my text gets all outta whack. I have rea
-
I have multiple Web Help Projects that I want to convert to one HTML Project so that there is only one project to manage. I don't want to link from a master project, I want it all embedded in the one projectso that I end up with one .xpj Help file. I
-
Alternative VIs for In Port.vi and Out Port.vi for 64 bit Windows 7 platform
Hi Need to use the printer port for my application. In Port and Out Port VIs was the simplest option in 32 bit Windows XP machine. Now I hear In Port and Out Port VIs are not supported in 64 bit Windows ( VISTA/7) machine. Is there any working altern
-
Question as to why I can't read online pdfs
I am unable to read pdfs in Safari. Suddenly. I have Adobe Reader 11.0.04. What should I do?