Inner Join Select query
hello all,
Below is a inner join query
SELECT aebeln aebelp apackno bzekkn b~ps_psp_pnr
FROM ( ( ekpo AS a INNER JOIN ekkn AS b
ON aebeln = bebeln
AND aebelp = bebelp )
INNER JOIN prps AS c
ON bps_psp_pnr = cpspnr )
INTO TABLE t_wbspo
WHERE a~ebeln IN s_ebeln
AND c~psphi IN s_psphi
AND stufe = c_task.
I want to modify this select and put one more join on ekkn-aufnr
and aufk-afunr .
Now for this i write the below code
SELECT aebeln aebelp apackno bzekkn bps_psp_pnr baufnr
FROM ( ( ( ekpo AS a INNER JOIN ekkn AS b
ON aebeln = bebeln
AND aebelp = bebelp )
INNER JOIN prps AS c
ON bps_psp_pnr = cpspnr )
INNER JOIN aufk AS d
ON baufnr = daufnr )
INTO TABLE t_wbspo
WHERE a~ebeln IN s_ebeln
AND c~psphi IN s_psphi
AND d~aufnr IN s_aufnr
AND stufe = c_task.
By the above way does it puts a join on ekkn-aufnr and aufk-aufnr ?
Is the above way the right way to do it ?
Please confirm
regards
Hello Bhanu,
Do you face any performance issue? Query looks good now, further you can refer to following threads to know more on JOIN-
Re: Inner join
http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ec77446011d189700000e8322d00/frameset.htm
Thank You,
Nishikant Kumbhar.
Similar Messages
-
Dynamic table name in an inner join - select statement
Hi,
Please can you let me know if is possible to use a Dynamic table name in an inner join?
Something like the statement below? (It works in a simple select statement but not in an inner join)
SELECT *
INTO CORRESPONDING FIELDS OF <t_itab>
FROM <Dynamic table name> INNER JOIN pa0050 ON
( <Dynamic table name>pernr = pa0050pernr )
WHERE <Dynamic table name>~pernr = it_pernr-l_pernr
AND pa0050~bdegr = f_bdegr.
Any help would be apprecited very much.
Thanks & Regards.Hi,
Check this link.
[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
[Re: accessing dynamic internal table's fields??;
hope it'll help u.
Regards,
Sneha.
Edited by: sneha kumari on Jun 18, 2009 1:57 PM -
Inner join-select -primary key in table issue
Hi ,
Iam using FEBKO(header) and FEBEP(item) in inner join select .But the datas fetching by this selct in not correct.The analysis is the is no common primary fields in the both table.
Question 1-> Can i use inner join without common primary key in the both tables, weather it possible to make a select without common primary key in both table. Please kindly let me know.
Question 2-> What is the other possible way to give the selct for both table(better performance)
Regards,
VeeraHi,
When you use INNER JOIN in this case, link your tables based on KUKEY and ESNUM fields, bcoz there can be many items under a single header. So this will work for you, even from the performance point of view.
Hope this is helpful to you. If you need further information, revert back.
Reward all the helpful answers.
Regards
Nagaraj T -
Hi, Please help on the Select Join query. I want to compare code_stat_system1/code_stat_system2 and code_date_system1 /code_date_system2 column from table #system1 and #system2 but there is 2 rule to get correct row from table #system1 and #system2.
Rule 1: We need to get max(code_date_system1) record from #system1 for every code_system1 for compare.
Rule 1: We need to get max(code_date_system2) record from #system2 BUT BEFORE THE RECORD OF 'DKNOW' OF code_stat_system2 for every code_system2 for compare.
drop table #system1,#system2
create table #system1
(Code_system1 varchar(10),code_stat_system1 varchar(10),code_date_system1 datetime)
Insert into #system1 values ('10','Dead','2013-01-01')
Insert into #system1 values ('10','Dead','2013-12-30')
Insert into #system1 values ('10','UnOpen','2014-10-01')
Insert into #system1 values ('10','Open','2014-11-01') --This record should max(code_stat_system1) for compare
Insert into #system1 values ('20','Dead','2013-12-01')
Insert into #system1 values ('20','Dead','2013-12-30')
Insert into #system1 values ('20','Open','2014-08-01')
Insert into #system1 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system1) for compare
create table #system2
(Code_system2 varchar(10),code_stat_system2 varchar(10),code_date_system2 datetime)
Insert into #system2 values ('10','Dead','2013-01-01')
Insert into #system2 values ('10','Dead','2013-12-30')
Insert into #system2 values ('10','Open','2014-10-01')
Insert into #system2 values ('10','UnOpen','2014-12-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('10','DKNOW','2015-01-01')
Insert into #system2 values ('10','DKNOW','2015-02-01')
Insert into #system2 values ('20','Dead','2013-12-01')
Insert into #system2 values ('20','Dead','2013-12-30')
Insert into #system2 values ('20','Open','2014-08-01')
Insert into #system2 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('20','DKNOW','2015-01-01')
Insert into #system2 values ('20','DKNOW','2015-02-01')
--Desired Output
Code_system1 code_stat_system1 code_date_system1 Code_system1 code_stat_system2 code_date_system1 Rrmk_code_stat Rrmk_code_date
10 Open 2014-11-01 10 UnOpen
2014-12-01 Codes not matching Dates not matching
20 UnOpen 2014-09-01 20 UnOpen
2014-09-01 Codes matching Dates matching
Thanks.drop table #system1,#system2
create table #system1
(Code_system1 varchar(10),code_stat_system1 varchar(10),code_date_system1 datetime)
Insert into #system1 values ('10','Dead','2013-01-01')
Insert into #system1 values ('10','Dead','2013-12-30')
Insert into #system1 values ('10','UnOpen','2014-10-01')
Insert into #system1 values ('10','Open','2014-11-01') --This record should max(code_stat_system1) for compare
Insert into #system1 values ('20','Dead','2013-12-01')
Insert into #system1 values ('20','Dead','2013-12-30')
Insert into #system1 values ('20','Open','2014-08-01')
Insert into #system1 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system1) for compare
create table #system2
(Code_system2 varchar(10),code_stat_system2 varchar(10),code_date_system2 datetime)
Insert into #system2 values ('10','Dead','2013-01-01')
Insert into #system2 values ('10','Dead','2013-12-30')
Insert into #system2 values ('10','Open','2014-10-01')
Insert into #system2 values ('10','UnOpen','2014-12-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('10','DKNOW','2015-01-01')
Insert into #system2 values ('10','DKNOW','2015-02-01')
Insert into #system2 values ('20','Dead','2013-12-01')
Insert into #system2 values ('20','Dead','2013-12-30')
Insert into #system2 values ('20','Open','2014-08-01')
Insert into #system2 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('20','DKNOW','2015-01-01')
Insert into #system2 values ('20','DKNOW','2015-02-01')
;with mycte1 as (select * ,row_number() Over (partition by Code_system1 Order by code_date_system1 Desc ) rn from #system1)
,mycte2 as (select *,row_number() Over (partition by Code_system2 Order by code_date_system2 Desc ) rn2 from #system2
where code_stat_system2<>'DKNOW')
Select m1.Code_system1, m1.code_stat_system1, m1.code_date_system1, Code_system2, code_stat_system2,code_date_system2 ,
case When code_date_system1=code_date_system2 then 'Dates matching' else 'Dates not matching' End as checkDate,
case When code_stat_system1=code_stat_system2 then 'Codes matching' else 'Codes not matching' End as checkStat
from mycte1 m1 inner join mycte2 m2 on m1.Code_system1= m2.Code_system2 and m1.rn=m2.rn2
Where m1.rn=1 -
How to do an INNER JOIN sub-query?
Can't seem to find anything that would help me out with this.
My prototype query goes like this but its giving me a ORA-00905: missing keyword
SELECT Poker_Site.site_name, bonus.sign_up_bonus
FROM poker_site
INNER JOIN bonus
WHERE Poker_site.site_name = 'Poker Stars'
ON Poker_Site.site_name = bonus.site_name;INNER JOIN join must be immediately followed by ON and only then by WHERE:
SELECT Poker_Site.site_name, bonus.sign_up_bonus
FROM poker_site
INNER JOIN bonus
ON Poker_Site.site_name = bonus.site_name
WHERE Poker_site.site_name = 'Poker Stars';SY. -
How to do outer join select query for an APEX report
Hello everyone,
I am Ann.
I have one select statement that calculate the statistics for one month(October 2012 in this example)
select ph.phase_number
, sum ( (case
WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE('Oct 2012','MON YYYY'))
THEN last_day(TO_DATE('Oct 2012','MON YYYY'))
ELSE ph.date_finished
END )
- ph.date_started + 1) / count(def.def_id) as avg_days
from phase_membership ph
inner join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
inner join defendant def on ce.defendant_id = def.def_id
where def.active = 1
and ph.date_started <= last_day(TO_DATE('Oct 2012','MON YYYY'))
and ph.active = 1
and UPPER(ce.court_name) LIKE '%'
group by rollup(phase_number)
Result is as below
Phase_Number AVG_DAYS
Phase One 8.6666666666666667
Phase Two 14.6
Phase Three 12
11.4615365
I have other select list mainly list the months between two date value.
select to_char(which_month, 'MON YYYY') as display_month
from (
select add_months(to_date('Aug 2012','MON YYYY'), rownum-1) which_month
from all_objects
where
rownum <= months_between(to_date('Oct 2012','MON YYYY'), add_months(to_date('Aug 2012','MON YYYY'), -1))
order by which_month )
Query result is as below
DISPLAY_MONTH
AUG 2012
SEP 2012
OCT 2012
Is there any way that I can join these two select statement above to generate a result like:
Month Phase Number Avg days
Aug 2012 Phase One 8.666
Sep 2012 Phase One 7.66
Oct 2012 Phase One 5.66
Aug 2012 Phase Two 8.666
Sep 2012 Phase Two 7.66
Oct 2012 Phase Two 5.66
Aug 2012 Phase Three 8.666
Sep 2012 Phase Three 7.66
Oct 2012 Phase Three 5.66
Or
Month Phase Number Avg days
Aug 2012 Phase One 8.666
Aug 2012 Phase Two 7.66
Aug 2012 Phase Three 5.66
Sep 2012 Phase One 8.666
Sep 2012 Phase Two 7.66
Sep 2012 Phase Three 5.66
Oct 2012 Phase One 8.666
Oct 2012 Phase Two 7.66
Oct 2012 Phase Three 5.66
And it can be order by either Phase Number or Month.
My other colleague suggest I should use an left outer join but after trying so many ways, I am still stuck.
One of the select I tried is
select a.display_month,b.* from (
select to_char(which_month, 'MON YYYY') as display_month
from (
select add_months(to_date('Aug 2012','MON YYYY'), rownum-1) which_month
from all_objects
where
rownum <= months_between(to_date('Oct 2012','MON YYYY'), add_months(to_date('Aug 2012','MON YYYY'), -1))
order by which_month )) a left outer join
( select to_char(ph.date_finished,'MON YYYY') as join_month, ph.phase_number
, sum ( (case
WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE(a.display_month,'MON YYYY'))
THEN last_day(TO_DATE(a.display_month,'MON YYYY'))
ELSE ph.date_finished
END )
- ph.date_started + 1) / count(def.def_id) as avg_days
from phase_membership ph
inner join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
inner join defendant def on ce.defendant_id = def.def_id
where def.active = 1
and ph.date_started <= last_day(TO_DATE(a.display_month,'MON YYYY'))
and ph.active = 1
and UPPER(ce.court_name) LIKE '%'
group by to_char(ph.date_finished,'MON YYYY') , rollup(phase_number)) b
on a.display_month = b.join_month
but then I get an error
SQL Error: ORA-00904: "A"."DISPLAY_MONTH": invalid identifier
I need to display a report on APEX with option for people to download at least CSV format.
I already have 1 inteactive report in the page, so don’t think can add another interactive report without using the iframe trick.
If any of you have any ideas, please help.
Thanks a lot.
AnnFirst of all, a huge thanks for following this Frank.
I have just started working here, I think the Oracle version is 11g, but not sure.
To run Oracle APEX version 4, I think they must have at least 10g R2.
This report is a bit challenging for me.I has never worked with PARTITION before.
About the select query you suggested, I run , and it seems working fine, but if I try this,
it return error ORA-01843: not a valid month
DEFINE startmonth = "Aug 2012";
DEFINE endmonth = "Oct 2012";
WITH all_months AS
select add_months(to_date('&startmonth','MON YYYY'), rownum-1) AS which_month
, add_months(to_date('&startmonth','MON YYYY'), rownum ) AS next_month
from all_objects
where
rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
select TO_CHAR (am.which_month, 'Mon YYYY') AS month
, ph.phase_number
, sum ( (case
WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE(am.which_month,'MON YYYY'))
THEN last_day(TO_DATE(am.which_month,'MON YYYY'))
ELSE ph.date_finished
END )
- ph.date_started + 1) / count(def.def_id) as avg_days
FROM all_months am
LEFT OUTER JOIN phase_membership ph PARTITION BY (ph.phase_number)
ON am.which_month <= ph.date_started
AND am.next_month > ph.date_started
AND ph.date_started <= last_day(TO_DATE(am.which_month,'MON YYYY')) -- May not be needed
AND ph.active = 1
LEFT OUTER join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
and ce.court_name IS NOT NULL -- or something involving LIKE
LEFT OUTER join defendant def on ce.defendant_id = def.def_id
AND def.active = 1
group by rollup(phase_number, am.which_month)
ORDER BY am.which_month
, ph.phase_number
;Here is the shorted versions of the three tables:
A_DEFENDANT, A_ENGAGEMENT, A_PHASE_MEMBERSHIP
CREATE TABLE "A_DEFENDANT"
"DEF_ID" NUMBER NOT NULL ENABLE,
"FIRST_NAME" VARCHAR2(50 BYTE),
"SURNAME" VARCHAR2(20 BYTE) NOT NULL ENABLE,
"DOB" DATE NOT NULL ENABLE,
"ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
CONSTRAINT "A_DEFENDANT_PK" PRIMARY KEY ("DEF_ID"))
Sample Data
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (101,'Joe','Bloggs',to_date('12/12/99','DD/MM/RR'),1);
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (102,'John','Smith',to_date('20/05/00','DD/MM/RR'),1);
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (103,'Jane','Black',to_date('15/02/98','DD/MM/RR'),1);
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (104,'Minnie','Mouse',to_date('13/12/88','DD/MM/RR'),0);
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (105,'Daisy','Duck',to_date('05/08/00','DD/MM/RR'),1);
CREATE TABLE "A_ENGAGEMENT"
"ENGAGEMENT_ID" NUMBER NOT NULL ENABLE,
"COURT_NAME" VARCHAR2(50 BYTE) NOT NULL ENABLE,
"DATE_REFERRED" DATE,
"DETERMINATION_HEARING_DATE" DATE,
"DATE_JOINED_COURT" DATE,
"DATE_TREATMENT_STARTED" DATE,
"DATE_TERMINATED" DATE,
"TERMINATION_TYPE" VARCHAR2(50 BYTE),
"ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
"DEFENDANT_ID" NUMBER,
CONSTRAINT "A_ENGAGEMENT_PK" PRIMARY KEY ("ENGAGEMENT_ID"))
Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (1,'AA',to_date('12/08/12','DD/MM/RR'),null,to_date('12/08/12','DD/MM/RR'),null,null,null,1,101);
Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (2,'BB',to_date('01/09/12','DD/MM/RR'),null,to_date('02/09/12','DD/MM/RR'),null,null,null,1,102);
Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (3,'AA',to_date('02/09/12','DD/MM/RR'),null,to_date('15/09/12','DD/MM/RR'),null,null,null,1,103);
Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (4,'BB',to_date('01/10/12','DD/MM/RR'),null,to_date('02/10/12','DD/MM/RR'),null,null,null,1,105);
CREATE TABLE "A_PHASE_MEMBERSHIP"
"MPM_ID" NUMBER NOT NULL ENABLE,
"MPM_ENG_ID" NUMBER NOT NULL ENABLE,
"PHASE_NUMBER" VARCHAR2(50 BYTE),
"DATE_STARTED" DATE NOT NULL ENABLE,
"DATE_FINISHED" DATE,
"NOTES" VARCHAR2(2000 BYTE),
"ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
CONSTRAINT "A_PHASE_MEMBERSHIP_PK" PRIMARY KEY ("MPM_ID"))
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (1,1,'PHASE ONE',to_date('15/09/12','DD/MM/RR'),to_date('20/09/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (2,1,'PHASE TWO',to_date('21/09/12','DD/MM/RR'),to_date('29/09/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (3,2,'PHASE ONE',to_date('12/09/12','DD/MM/RR'),null,null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (4,3,'PHASE ONE',to_date('20/09/12','DD/MM/RR'),to_date('01/10/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (5,3,'PHASE TWO',to_date('02/10/12','DD/MM/RR'),to_date('15/10/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (6,4,'PHASE ONE',to_date('03/10/12','DD/MM/RR'),to_date('10/10/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (7,3,'PHASE THREE',to_date('17/10/12','DD/MM/RR'),null,null,0);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (8,1,'PHASE THREE',to_date('30/09/12','DD/MM/RR'),to_date('16/10/12','DD/MM/RR'),null,1);
The requirements are:
The user must be able to request the extract for one or more calendar months, e.g.
May 2013
May 2013 – Sep 2013.
The file must contain a separate row for each calendar month in the requested range. Each row must contain the statistics computed for that calendar month.
The file must also include a row of totals.
The user must be able to request the extract for either Waitakere or Auckland or Consolidated (both courts’ statistics accumulated).
Then the part that I am stuck is
For each monitoring phase:
Phase name (e.g. “Phase One”)
Avg_time_in_phase_all_particip
for each phase name,
Add up days in each “phase name” Monitoring Phase, calculated as:
If Monitoring Phase.Date Finished is NULL or > month end date,
+(*Month end date* Minus Monitoring Phase.Date Started Plus 1)+
Otherwise (phase is complete)
+(Monitoring Phase.Date Finished Minus Monitoring Phase.Date Started Plus 1.)+
Divide by the numbers of all participants who have engaged in “phase name”.
This is the words of the Business Analyst,
I try to do as required but still struggle to identify end_month for the above formula to display for the range of months.
Of course, I can write two nested cursor. The first one run the list of month, then for each month, run the parameterised report.
But I prefer if possible just use SQL statements, or at least a PL/SQL but return a query.
With this way, I can create an APEX report, and use their CSV Extract function.
Yes, you are right, court_name is one of the selection parameters.
And the statistics is not exactly for one month. It is kind of trying to identify all phases that are running through the specified month (even phase.date_started is before the month start).
This is the reason why I put the condition AND ph.date_started <= last_day(TO_DATE('Oct 2012','MON YYYY')) (otherwise I get negative avg_days)
User can choose either one court "AA" or "BB" or combined which is all figures.
Sorry for bombarding you a lot of information.
Thanks a lot, again.
Edited by: Ann586341 on Oct 29, 2012 9:57 PM
Edited by: Ann586341 on Oct 29, 2012 9:59 PM -
Hi all,
I have a query, but it doesn't work when i give select-options range table in WHERE clause.
SELECT-OPTIONS :
l_bukrs FOR WA_INPUT-bukrs NO INTERVALS ,
SELECT
VBAK~BUKRS_VF AS BUKRS "COMPANY CODE
PA0001~ENAME "SALES EMPLOYEE NAME
KNA1~NAME1 "CLIENT
VBKD~BSTKD "PO NO
VBAK~VBELN "SO NO
VBAK~AUDAT "SO DATE
VBAP~POSNR "LINE
VBAP~KWMENG "QTY
VBAP~VRKME "UNIT
VBAP~NETPR "RATE
VBAP~NETWR "ORDER VALUE
VBAP~WAERK "DOCUEMNT CURRENCY
VBAP~MATNR "MATERIAL NO
VBAP~ARKTX "MATERIAL NAME
VBKD~KURSK "EXCHANGE RATE
INTO CORRESPONDING FIELDS OF TABLE IT_OPSALES
FROM VBAP
LEFT OUTER JOIN VBPA ON VBPAVBELN = VBAPVBELN AND VBPA~PARVW = 'AF'
INNER JOIN PA0001 ON PA0001PERNR = VBPAPERNR
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN KNA1 ON KNA1KUNNR = VBAKKUNNR
INNER JOIN VBKD ON VBKDVBELN = VBAKVBELN AND VBKDPOSNR = VBAPPOSNR
WHERE BUKRS IN L_BUKRS
it wont support when i give L_bukrs in inner join clause..!!
any idea to change the query??
thaks and regards
JoseHi,
Declare the select option as s_bukrs .
SELECT-OPTIONS :
S_bukrs FOR WA_INPUT-bukrs NO INTERVALS ,
SELECT
VBAK~BUKRS_VF AS BUKRS "COMPANY CODE
PA0001~ENAME "SALES EMPLOYEE NAME
KNA1~NAME1 "CLIENT
VBKD~BSTKD "PO NO
VBAK~VBELN "SO NO
VBAK~AUDAT "SO DATE
VBAP~POSNR "LINE
VBAP~KWMENG "QTY
VBAP~VRKME "UNIT
VBAP~NETPR "RATE
VBAP~NETWR "ORDER VALUE
VBAP~WAERK "DOCUEMNT CURRENCY
VBAP~MATNR "MATERIAL NO
VBAP~ARKTX "MATERIAL NAME
VBKD~KURSK "EXCHANGE RATE
INTO CORRESPONDING FIELDS OF TABLE IT_OPSALES
FROM VBAP
LEFT OUTER JOIN VBPA ON VBPAVBELN = VBAPVBELN AND VBPA~PARVW = 'AF'
INNER JOIN PA0001 ON PA0001PERNR = VBPAPERNR
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN KNA1 ON KNA1KUNNR = VBAKKUNNR
INNER JOIN VBKD ON VBKDVBELN = VBAKVBELN AND VBKDPOSNR = VBAPPOSNR
WHERE BUKRS IN S_BUKRS
Hope this helps you.
Thanks & Regards,
Y.R.Prem Kumar -
I had my data declaration as below.
DATA :BEGIN OF t_plaf OCCURS 0,
normt LIKE mara-normt,
matnr LIKE plaf-matnr,
pwwrk LIKE plaf-pwwrk,
paart LIKE plaf-paart,
verid LIKE plaf-verid,
auffx LIKE plaf-auffx,
psttr LIKE plaf-psttr,
gsmng LIKE plaf-gsmng,
END OF t_plaf.
corresponding inner join statement
SELECT maranormt plafmatnr
plafpwwrk plafpaart plaf~verid
plafauffx plafpsttr plaf~gsmng
INTO TABLE t_plaf
FROM plaf
INNER JOIN mara
ON plafmatnr EQ maramatnr
WHERE plaf~paart = 'LA'.
Now I have changed the declaration as below
DATA : BEGIN OF t_plaf OCCURS 0,
normt LIKE mara-normt.
INCLUDE STRUCTURE plaf.
DATA : END OF t_plaf.
now i have changed the data declaration as mentioned above and need a inner join statement for the data declaration i have specified.
Any suggestions,
MAdhuHi Madhu,
USE INTO CORRESPONDING option instead of INTO TABLE.
SELECT maranormt plafmatnr
plafpwwrk plafpaart plaf~verid
plafauffx plafpsttr plaf~gsmng
<b>INTO CORRESPONDING FIELDS OF TABLE t_plaf</b>
FROM plaf
INNER JOIN mara
ON plafmatnr EQ maramatnr
WHERE plaf~paart = 'LA'.
Thanks,
Vinay -
CSOM (Javascript) Inner join CAML query on 'User Information List'
I need to pull site user details like (email, display name, phone) from 'User information list' using a 'inner join' on a different list 'SiteOwners' where 'Contact' is a person or group field.
The result object is not returning the details from 'User Information List' though it returns details from 'SiteOwners' list
<script src="/_layouts/15/SP.runtime.js" type="text/javascript"></script>
<script src="/_layouts/15/SP.js" type="text/javascript"></script>
<script type='text/javascript'>
'use strict';
//$(document).ready(function() {
function abc() {
var context = SP.ClientContext.get_current();
var web =context.get_web();
var stownrlist = web.get_lists().getByTitle('SiteOwners');
var camlqry = new SP.CamlQuery();
camlqry.set_viewXml = "<View>" +
"<Query></Query>" +
"<ViewFields>" +
"<FieldRef Name='Title'/>" +
"<FieldRef Name='Contact'/>" +
"<FieldRef Name='UserName'/>" +
"<FieldRef Name='UserEMail'/>" +
"<FieldRef Name='UserMobilePhone'/>" +
"</ViewFields>" +
"<ProjectedFields>" +
"<Field Name='UserName' Type='Lookup' List='User Information List' ShowField='Name' />" +
"<Field Name='UserEMail' Type='Lookup' List='User Information List' ShowField='EMail' />" +
"<Field Name='UserMobilePhone' Type='Lookup' List='User Information List' ShowField='MobilePhone' />" +
"</ProjectedFields>" +
"<Joins>" +
"<Join Type='INNER' ListAlias='User Information List'>" +
"<Eq>" +
"<FieldRef Name='Contact' RefType='Id'/>" +
"<FieldRef List='User Information List' Name='ID'/>" +
"</Eq>" +
"</Join>" +
"</Joins>" +
"</View>";
debugger;
var stownritems = stownrlist.getItems(camlqry);
context.load(stownritems);//, 'Include(Title,Contact,UserName,UserEMail,UserMobilePhone)');
context.executeQueryAsync(
Function.createDelegate(this, function () {
debugger;
var stownenm = stownritems.getEnumerator();
while (stownenm.moveNext()) {
var userid, loginname,email,name,mobilephone;
if (stownenm.get_current().get_item('Contact') != null) {
userid = stownenm.get_current().get_item('Contact').get_lookupId();
loginname = stownenm.get_current().get_item('Contact').get_lookupValue();
email = stownenm.get_current().get_item('ows_UserEMail');
name = stownenm.get_current().get_item('UserName');
mobilephone = stownenm.get_current().get_item('UserMobilePhone');
}), function() {alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());});
</script>
Any suggestions / help please.
SaiI identified the issue
"camlqry.set_viewXml" is a method (camlqry.set_viewXml()) not a property (as apposed to C#).
The above should be like "camlqry.set_viewXml(querystring)" instead of "camlqry.set_viewXml =qrystring".
Sai -
Hi,
I need a suggestion for improvement of my inner JOIN statement.
internal table itab is of below type
type: begin of ty_itab
field a
field b
field c
field d
end of ty_itab
I have to join two database table TABLE1 and TABLE2. Fields a and d are from TABLE2 and fields b and c are from TABLE 1.
But in the internal table I must have the fields in the order fielda,b,c,d.
Which of the below two options will be better for performance ? And why ?
option 1:
SELECT tab2~a
tab1~b
tab1~c
tab2~d into corresponding fields of itab from TABLE1 as tab1 and TABLE2 as tab2 on..........
option2:
SELECT tab1~b
tab1~c
tab2~a
tab2~d into corresponding fields of itab from TABLE1 as tab1 and TABLE2 as tab2 on..........
Thanks in advance...
Best Regards
Ananya Mukherjee
Moderator message - Cross post locked
Edited by: Rob Burbank on May 28, 2009 9:43 AMI am not satisfied with your two options. Because of following reason,
1. First I want to know which one is master table and item table. Because in inner join select query you want to use master table as first and you want to use the item table as second.
Example:
SELECT TAB2A TAB1B TAB1C TAB2D
INTO TABLE ITAB
FROM <MASTER TABLE1> AS TAB1 INNER JOIN <ITEM TABLE2> AS TAB2 ON..........
2. You should not use the INTO CORRESPONDING FIELDS OF ITAB. Instead of this you can change the field order in internal table or in select query.
Example:
Use following way
TYPE: BEGIN OF TY_ITAB
FIELD A
FIELD B
FIELD C
FIELD D
END OF TY_ITAB
SELECT TAB2A TAB1B TAB1C TAB2D
INTO TABLE ITAB
FROM <MASTER TABLE1> AS TAB1 INNER JOIN <ITEM TABLE2> AS TAB2 ON..........
Or , Anyway you are going to use in program only. It will not affect your logic if change the field order in the internal table.
TYPE: BEGIN OF TY_ITAB
FIELD B
FIELD C
FIELD A
FIELD D
END OF TY_ITAB
SELECT TAB1B TAB1C TAB2A TAB2D
INTO TABLE ITAB
FROM <MASTER TABLE1> AS TAB1 INNER JOIN <ITEM TABLE2> AS TAB2 ON..........
3. In inner join query, the order of Where condition also create the perform issue. Because in where condition maximum you try to use all the primary key from <MASTER TABLE1> and <ITEM TABLE2> and field order in where condition should be same order in <MASTER TABLE1> and <ITEM TABLE>.
This are the things you want to take care when you try to use INNER JOIN Query. If you have any clarification please let me know. I will try answer your Questions.
Ravi.
Edited by: RavivarmanP on May 28, 2009 6:55 PM -
Can I di Inner Join on 2 tables by using only 1 key field?
Hello,
I hv 2 Std. SAP tables, KNVV, KNKK.
- KNVV - does hv 2 key fields (KUNNR and some other, say X)
- KNKK - does hv 2 key fields (KUNNR and some other,say Y)
I want to build a inner join on these 2 tables.
So, Can I do a INNER JOIN on these 2 tables by using ONLY one key field (its KUNNR)? bcoz, there is ONLY common field!!
thank youHi,
The correctness depends on your bussiness requirement. If the common key field is not a primary key, you may end up fetching duplicate entries which you may have to delete after the select query. You dont have to take of any extra precautions in a inner join select query compared to a ordinary select query. Just make sure you use most of the primary key fields of both the tables in the where clause of the select query for better performance
Vikranth -
Hi,
Please give me the Select query
I have to fetch EBELN,BUKRS,LIFNR,BSART,EKORG,EKGRP,WAERS,WKURS from EKKO and
EBELP,LGORT,MATKL ,WERKS,BEDNR,IDNLF,BPRME,NETPR from EKPO and
MENGE, SAKTO,AUFNR,ANLN1,GSBER,PS_PSP_PNR from EKKN and
LPEIN,EINDT,SLFDT, from EKET.
I have to fetch all the data into an single internal table(Mandatory) by a select query using Joins.
EKKO is having EBELN as primary key
EKPO is having EBELN,EBELP as primary key
EKKN is having EBELN,EBELP as primary key
EKET is having EBELN,EBELP as primary key
Can anybody Please give me the Select query.
With Regards
AjayHi ,
I am sending this sample coed for the Inner joins .Hope this will help you:
Inner joins using 3 tables
Try this :-
SELECT stpostlnr stpoidnrk mastmatnr maramtart stpo~menge
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast
JOIN stpo ON stpostlnr = maststlnr
JOIN mara ON maramatnr = mastmatnr
WHERE stpostlty = 'M' "AND stpoidnrk IN s_matnr
AND mast~werks = 1000.
Here s_matnr is a select-options on the selection-screen.
Or this.
Code:
Select single VbrkBukrs VbrkKunrg Vbrk~Vbeln
VbrkFkdat VbrkBstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
VbakVbeln VbakBstdk
LikpVbeln Likplfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on TvzbtZterm = VbrkZterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on VbakVbeln = SalesLnkVbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on LikpVbeln = DeliveryLnkVbelv
where vbrk~vbeln = pu_Vbeln.
This code locates sales, delivery and payment terms info from a billing document number.
or
Here, this one also works fine :
select zfpcdcadivi zfpcdproforma zfpcdfactura zfpcdaniofactura
zfpcdmontousd zfpcdmontoap zfpcdebeln zfpcdinco1
zfpcdlifnr lfa1name1 zcdvsstatus zfpcdconint
into it_lista
from zfpcd inner join zcdvs
on zfpcdebeln = zcdvsebeln
and zfpcdproforma = zcdvsproforma
and zfpcdlifnr = zcdvslifnr
inner join lfa1
on zfpcdlifnr = lfa1lifnr
where zcdvs~status = '04'.
Also Here is another solution that just uses inner joins:
SELECT vbakvbeln vbfaerdat INTO (itab-vbeln, itab-wadat)
FROM ( vbak INNER JOIN vbap
ON vbapvbeln = vbakvbeln )
INNER JOIN vbfa ON vbakvbeln = vbfavbelv
WHERE vbak~kunnr = m_wm AND
vbak~vbtyp = 'C' AND
vbfa~erdat IN s_date AND
vbap~matnr = 'MZ1807F' AND
vbfaposnv = vbapposnr AND
vbfa~vbtyp_n = 'J'.
<REMOVED BY MODERATOR>
Cheers,
Chandra Sekhar.
Edited by: Alvaro Tejada Galindo on Apr 10, 2008 5:20 PM -
Strange result from insert into...select query
Hello guys,
I need your preciuos help for a question maybe simple, but that I can't explain by myself!
I have a query of "insert into...select" that, as I have explained in the title, returns a strange result. In facts, If I execute ONLY the SELECT statement the query returns the expected result (so 2 rows); instead If I execute the entire statement, that is the "insert into...select", the query returns 0 rows inserted!!
Following an example of the query:
INSERT
INTO TITOLI_ORI
COD_TITOLO_RICCONS ,
D_ESTRAZIONE ,
COD_SOCIETA ,
COD_PIANO_CONTABILE ,
COD_CONTO_CONTABILE ,
COD_RUBRICATO_STATISTICO_1 ,
COD_NDG ,
NUM_ESEGUITO ,
CUR_IMPORTO_RICCONS ,
CUR_IMPORTO_BICO ,
FLG_MODIFICATO ,
CUR_NON_ASSEGNATO ,
FLG_QUOTATO ,
COD_CATEG ,
TIP_COPERTURA ,
TIPTAS_TITOLO
SELECT NEWID,
'28-feb-2111',
COD_SOCIETA,
COD_PIANO_CONTABILE,
COD_CONTO_CONTABILE,
COD_RUBRICATO_STATISTICO_1,
COD_NDG,
NUM_ESEGUITO,
CUR_VAL_IMPEGNI,
'ABC' as CUR_IMPORTO_BICO,
0 as FLG_MODIFICATO,
NULL as CUR_NON_ASSEGNATO,
FLG_QUOTATO,
COD_CATEG,
TIP_COPERTURA,
TIP_TASSO
FROM
(SELECT S.COD_SOC AS COD_SOCIETA,
S.TIP_PIANO_CNTB AS COD_PIANO_CONTABILE,
S.COD_CONTO_CNTB AS COD_CONTO_CONTABILE,
S.COD_RUBR_STAT AS COD_RUBRICATO_STATISTICO_1,
TRC.COD_RAGGR_IAS AS COD_RAGGRUPPAMENTO_IAS,
TRC.COD_NDG AS COD_NDG,
TRC.COD_ESEG AS NUM_ESEGUITO,
CAST((TRC.IMP_PLUS_MINUS_VAL/TRC.IMP_CAMB) AS FLOAT) AS CUR_VAL_IMPEGNI,
TRC.TIP_QUOTAZ AS FLG_QUOTATO,
TRC.COD_CAT_TIT AS COD_CATEG,
TIP_COP AS TIP_COPERTURA,
T.TIP_TASSO AS TIP_TASSO
FROM S_SLD_CNTB S
INNER JOIN
(SELECT DISTINCT COD_SOC,
TIP_PIANO_CNTB,
COD_CONTO_CNTB,
COD_RUBR_STAT ,
COD_INTER_TIT AS COD_INTER
FROM S_COLLEG_CONTO_CNTB_TIT
WHERE COD_SOC = 'ME'
) CCC
ON S.COD_SOC = CCC.COD_SOC
AND S.TIP_PIANO_CNTB = CCC.TIP_PIANO_CNTB
AND S.COD_CONTO_CNTB = CCC.COD_CONTO_CNTB
AND S.COD_RUBR_STAT = CCC.COD_RUBR_STAT
INNER JOIN S_TIT_RICCONS TRC
ON CCC.COD_INTER = TRC.COD_INTER_TIT
AND CCC.COD_SOC = TRC.COD_SOC
AND TRC.COD_RAGGR_IAS = RTRIM('VALUE1 ')
AND TRC.COD_RAGGR_IAS NOT IN ('VALUE2')
AND TRC.DES_TIP_SLD_TIT_RICCONS IN ('VALUE3')
AND TRC.DES_MOV_TIT = RTRIM('VALUE4 ')
AND TRC.COD_CAT_TIT = RTRIM('VALUE4 ')
AND TRC.COD_INTER_TIT = RTRIM('VALUE5')
AND '28-feb-2011' = TRC.DAT_RIF
LEFT JOIN S_TIT T
ON T.COD_INTER_TIT = TRC.COD_INTER_TIT
AND T.COD_SOC = TRC.COD_SOC
AND '28-feb-2011' = T.DAT_RIF
INNER JOIN S_ANAG_SOGG AG
ON TRC.COD_NDG = AG.COD_NDG
AND AG.COD_SOC = TRC.COD_SOC
AND '28-feb-2011' = AG.DAT_RIF
WHERE S.DAT_RIF = '28-feb-2011'
AND (S.FLG_ANULL_BICO = 0
OR S.FLG_ANULL_BICO IS NULL)
AND S.COD_SOC = 'V6'
AND LENGTH(RTRIM(S.COD_CONTO_CNTB)) = 10
AND S.TIP_PIANO_CNTB = 'V7'
AND TRC.IMP_PLUS_MINUS_VAL < 0
AND SUBSTR(S.COD_CONTO_CNTB,1,7) IN (RTRIM('VALUE8 '))
Thanks a lotRight, I have executed this steps:
- I have changed the query with the select count(*)
- Changed the insert into with the select count(*)
- Executed the insert into
These are the result:
SQL> select count(*) from TITOLI_ORI2;
COUNT(*)
1
BUT:
SQL> select * from TITOLI_ORI2;
A
0
The insert into that I've modified is this:
INSERT INTO bsc.TITOLI_ORI2
select count(*)
FROM
(SELECT bsc.NEWID,
TO_DATE('28-feb-2111','DD-MON-YYYY') as data,
COD_SOCIETA,
COD_PIANO_CONTABILE,
COD_CONTO_CONTABILE,
COD_RUBRICATO_STATISTICO_1,
COD_NDG,
NUM_ESEGUITO,
CUR_VAL_IMPEGNI,
'ABC' AS CUR_IMPORTO_BICO,
0 AS FLG_MODIFICATO,
NULL CUR_NON_ASSEGNATO,
FLG_QUOTATO,
COD_CATEG,
TIP_COPERTURA,
TIP_TASSO
FROM
(SELECT S.COD_SOC AS COD_SOCIETA,
S.TIP_PIANO_CNTB AS COD_PIANO_CONTABILE,
S.COD_CONTO_CNTB AS COD_CONTO_CONTABILE,
S.COD_RUBR_STAT AS COD_RUBRICATO_STATISTICO_1,
TRC.COD_RAGGR_IAS AS COD_RAGGRUPPAMENTO_IAS,
TRC.COD_NDG AS COD_NDG,
TRC.COD_ESEG AS NUM_ESEGUITO,
CAST((TRC.IMP_PLUS_MINUS_VAL/TRC.IMP_CAMB) AS FLOAT) AS CUR_VAL_IMPEGNI,
TRC.TIP_QUOTAZ AS FLG_QUOTATO,
TRC.COD_CAT_TIT AS COD_CATEG,
TIP_COP AS TIP_COPERTURA,
T.TIP_TASSO AS TIP_TASSO
FROM bsc.S_SLD_CNTB S
INNER JOIN
(SELECT DISTINCT COD_SOC,
TIP_PIANO_CNTB,
COD_CONTO_CNTB,
COD_RUBR_STAT ,
COD_INTER_TIT AS COD_INTER
FROM bsc.S_COLLEG_CONTO_CNTB_TIT
WHERE COD_SOC = 'ME'
) CCC
ON S.COD_SOC = CCC.COD_SOC
AND S.TIP_PIANO_CNTB = CCC.TIP_PIANO_CNTB
AND S.COD_CONTO_CNTB = CCC.COD_CONTO_CNTB
AND S.COD_RUBR_STAT = CCC.COD_RUBR_STAT
INNER JOIN bsc.S_TIT_RICCONS TRC
ON CCC.COD_INTER = TRC.COD_INTER_TIT
AND CCC.COD_SOC = TRC.COD_SOC
AND TRC.COD_RAGGR_IAS = RTRIM('HFT ')
AND TRC.COD_RAGGR_IAS NOT IN ('GPO')
AND TRC.DES_TIP_SLD_TIT_RICCONS IN ('DISPONIBILI')
AND TRC.DES_MOV_TIT = RTRIM('CONSEGNARE ')
AND TRC.COD_CAT_TIT = RTRIM('OBBLIGAZIONE ')
AND TRC.COD_INTER_TIT = RTRIM('334058')
AND '28-feb-2011' = TRC.DAT_RIF
LEFT JOIN bsc.S_TIT T
ON T.COD_INTER_TIT = TRC.COD_INTER_TIT
AND T.COD_SOC = TRC.COD_SOC
AND '28-feb-2011' = T.DAT_RIF
INNER JOIN bsc.S_ANAG_SOGG AG
ON TRC.COD_NDG = AG.COD_NDG
AND AG.COD_SOC = TRC.COD_SOC
AND '28-feb-2011' = AG.DAT_RIF
WHERE S.DAT_RIF = '28-feb-2011'
AND (S.FLG_ANULL_BICO = 0
OR S.FLG_ANULL_BICO IS NULL)
AND S.COD_SOC = 'ME'
AND LENGTH(RTRIM(S.COD_CONTO_CNTB)) = 10
AND S.TIP_PIANO_CNTB = 'IS'
AND TRC.IMP_PLUS_MINUS_VAL < 0
AND SUBSTR(S.COD_CONTO_CNTB,1,7) IN (RTRIM('P044C11 '))
Another time the strange result returns!!
And I've created the table TITOLI_ORI2 as create table TITOLI_ORI2 (a number); to contain the number result of the query. -
Inner join in ABAP and exporting the data
Hi,
I want to use inner join in ABAP for retrieving data from 2 tables and export that data.How will i do it?Hi,
Refer following code
*--Select query to pick the data from table VBRK
VBRP and VBPA using inner join
SELECT a~vbeln "Billing document
a~fkdat "Billing date
a~fktyp "Billing category
a~fkart "Billing type
a~vtweg "Distribution channel
a~knumv "Number of doc condition
b~posnr "Billing item
b~matnr "Material Number
b~werks "Plant
b~vgbel "Referance
b~netwr "Net value of billing item
b~wavwr "Cost in document currency
c~kunnr "Partner function
FROM vbrk AS a
INNER JOIN vbrp AS b
ON avbeln EQ bvbeln
INNER JOIN vbpa AS c
ON bvbeln EQ cvbeln
AND bposnr EQ cposnr
INTO CORRESPONDING FIELDS OF TABLE it_vbrp
WHERE fkdat IN s_erdat
AND parvw EQ 'ZS'.
IF sy-subrc EQ 0.
*--Sort table by
SORT it_vbrp BY vgbel1.
ENDIF.
Regards,
Prashant -
SELECT order_head.ID col
FROM
order order_head
INNER JOIN customer customer_2 ON order_head.customerID = customer_2.ID
WHERE
order_head.orderDate BETWEEN '12/12/2001'
AND '12/12/2009'
AND order_head.ID <> 0
AND customer_2.LastName = 'smith'
AND order_head.status = 1
INNER JOIN (customer_2 INNER JOIN order_head ON customer_2.ID = order_head.customerID) ON cust_address.ID = customer_2.AddressID )
WHERE cust_address.postcode = 'NW1 9PQ'
Error : Incorrect syntax near the keyword 'INNER'.
The last bit in bold does not work the other stuff works correctly, what I am trying to do that does not work is find orders from customers with last name of smith and post code of 'NW1 9PQ', it is unfortunate that the tables are from a third party and cannot be changed and so I am stuck with the table structure. I am also trying to stick with joins.
I have tested this inner join in isolation and appears to work fine !!!!
Any suggestions or pointers will be most appriciated, thanks in advance....
BM[email protected] wrote:
Error : Incorrect syntax near the keyword 'INNER'.
The last bit in bold does not work the other stuff works correctly, what I am trying to do that does not work is find orders from customers with last name of smith and post code of 'NW1 9PQ', it is unfortunate that the tables are from a third party and cannot be changed and so I am stuck with the table structure. I am also trying to stick with joins.
I have tested this inner join in isolation and appears to work fine !!!!
Any suggestions or pointers will be most appriciated, thanks in advance....BM,
probably you just need follow the correct syntax described in the previous post and put first the join operators. If you really think you have the need to use nested query, you could use an approach like that:
SELECT order_head.ID col
FROM order order_head
INNER JOIN customer customer_2 ON order_head.customerID = customer_2.ID
INNER JOIN (
select c2.* from customer c2 INNER JOIN order o2 ON c2.ID = o2.customerID
) cust_address ON cust_address.ID = customer_2.AddressID
WHERE order_head.orderDate BETWEEN '12/12/2001'
AND '12/12/2009'
AND order_head.ID <> 0
AND customer_2.LastName = 'smith'
AND order_head.status = 1
AND cust_address.postcode = 'NW1 9PQ'Probably above statement doesn't make sense content-wise but I just wanted to use it for illustrative purposes that you can use nested subqueries like that.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/
Maybe you are looking for
-
How to connect my PB to TV using Mini-DVI to Video Adapter
I went through the posts, so I'm sure this is a stupid question, but: I have a mini-dvi to video adapter for my powerbook, which I want to connect to my TV. What's the extra cable I need to connect the adapter to the TV?
-
I recently upgraded to Yosemite. When I send an Email, the receiver sees that it comes from my wife in their "from" column We have separatee signatures that I can chose from and our Email account is identified with both of our names. How do I change
-
Could someone please tell me why this doesn't work. app.activeDocument.PasteboardPreferences.minimumSpaceAboveAndBelow = 50mm The reported error is "Object does not support the method or property PasteboardPreferences" I has taken this straight out o
-
Scripting objects in Illustrator - JavaScript
Hi i am new to use Javascript in Illustrator. I can create new layers easy :-) but i like to select objects with a specific fillcolor All those objects should be moves to a specific layer And have an other fillcolor. Is this possible with JavaScript
-
Doing a Fresh Install on 2nd hand Mac
Hi, I have just purchased a 2nd hand system a external seller, I want to make sure there is nothing lurking on the system that should not be there and to create my own user etc. I have Mid 2011 27'' MAC AMD Radeon HD 6770M 512 MB 4GB RAM Intel i5 (Qu