Default join in select statements
Hi guyz,
If I am using just Join in my select statement. What does it do by default
1. innter join
2. outer join
eg:
select vbeln posnr into table itab from vbak <b>join</b> vbap on vbakvbeln = vbapvbeln.
Thanks.
Mgs,
By Default innerjoin.
See the diff.
Hi karan check also the "left outer join" statement.
It might help you if you need 1-N relation
// left outer Join
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Left Outer Join
|--||||||||--|
| A | B | C | D | D | E | F | G | H |
|--||||||||--|
| a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 |
| a3 | b3 | c3 | 2 |NULL|NULL|NULL|NULL|NULL|
| a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 |
|--||||||||--|
// Inner Join
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
Inner Join
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
1
e1
f1
g1
h1
a4
b4
c4
3
3
e2
f2
g2
h2
Pls. mark if useful
Similar Messages
-
Inner join in select statement
hi,
i am using select statement like
SELECT ekkoebeln ekkobukrs ekkobstyp ekkobsart ekko~ernam
ekkolifnr ekkozterm ekkozbd1t ekkozbd2t ekko~zbd3t
ekkozbd1p ekkozbd2p ekkoekorg ekkoekgrp ekko~waers
ekkowkurs ekkokufix ekkobedat ekkokdate
Begin of Changes, RICEF : 293.
ekkozzhedg ekkozzheda ekkozzpba ekkozzpbubu lfa1~vbund
End of Changes, RICEF . 293.
lfa1land1 lfa1name1
ekpa~lifn2
INTO CORRESPONDING FIELDS OF TABLE iekko
FROM ekko
JOIN lfa1 ON lfa1lifnr = ekkolifnr
LEFT JOIN ekpa ON ekpaebeln = ekkoebeln AND
ekpa~ebelp = '00000' AND
ekpa~parvw = 'RS'
FOR ALL entries IN icooi
WHERE ekko~ebeln = icooi-refbn
AND ekko~zzhedg IN s_zzhedg
AND ekko~zzheda IN s_zzheda.
where in ekko table ,the fields zzhedg and zzheda are appended..but in the debugging mode i am unable to see this 2 field....in the output also....so how should i write my select query?Hi,
Is your select statement returning sy-subrc 0. In debugging mode may be your fields may not be visible in the screen since your internal table has many fields, you have to press >> forward button to check the fields.
Thanks & Regards,
Navneeth K. -
Hi All,
I have 9 select Statements,i can combine these queries by 'UNION' to get the result....but the process will be tedious.
Is there any other option to do the same in a easy way.
Example :
SELECT ecv.creation_date "Initiation Date",
eceb.c_ext_attr1 "REPORTING PERSON",
eceb.c_ext_attr2 INITIATOR,
eceb.c_ext_attr3 "REPORTING PERSON TITLE",
eceb.d_ext_attr2 "AWARE DATE",
eceb.c_ext_attr4 TELEPHONE
FROM eng_changes_v ecv,
eng_changes_ext_b eceb
WHERE ecv.change_id = eceb.change_id
AND ecv.change_notice = 'COM-10034'
AND attr_group_id = 266;
UNION
SELECT eceb.c_ext_attr2 TYPE,
eceb.c_ext_attr3 INSTITUTION,
eceb.c_ext_attr4 TERRITORY,
eceb.c_ext_attr5 "CUSTOMER NAME",
eceb.c_ext_attr6 TITLE,
eceb.c_ext_attr7 ADDRESS,
eceb.c_ext_attr8 "ADDRESS 2",
eceb.c_ext_attr9 CITY,
eceb.c_ext_attr10 STATE,
eceb.n_ext_attr1 ZIP,
eceb.c_ext_attr11 COUNTRY,
eceb.c_ext_attr12 TELEPHONE,
eceb.c_ext_attr13 FAX
FROM eng_changes_v ecv,
eng_changes_ext_b eceb
WHERE ecv.change_id = eceb.change_id
AND ecv.change_notice = 'COM-10034'
AND attr_group_id = 267;
In this fashion i have 9 select statements.
Thanks in advance!
RamyaWell, this is not the silly EAV model …
but it does look as something that has been slightly abused on the dynamic/generic side.
You certainly do not want to UNION … it wouldn’t make sense anyway.
Think of your ATTR_GROUP_ID as identifiers of what could have been real tables
(dependents of ENG_CHANGES_V):
create view could_be_table_266 as
select change_id
,c_ext_attr1 REPORTING_PERSON
,c_ext_attr2 INITIATOR
,c_ext_attr3 REPORTING_PERSON_TITLE
,d_ext_attr2 AWARE_DATE
,c_ext_attr4 TELEPHONE
from eng_changes_ext_b
where attr_group_id = 266
create view could_be_table_267 as
select change_id
,c_ext_attr2 TYPE
,c_ext_attr3 INSTITUTION
,c_ext_attr4 TERRITORY
,c_ext_attr5 CUSTOMER NAME
,c_ext_attr6 TITLE
,c_ext_attr7 ADDRESS
,c_ext_attr8 ADDRESS_2
,c_ext_attr9 CITY
,c_ext_attr10 STATE
,n_ext_attr1 ZIP
,c_ext_attr11 COUNTRY
,c_ext_attr12 TELEPHONE
,c_ext_attr13 FAX
from eng_changes_ext_b
where attr_group_id = 267
Then join using your knowledge of what the “logical” relationship between these table would be … likely
select <columns_you_need_from x>
,<columns_you_need_from a>
,<columns_you_need_from b>
from eng_changes_v x
,could_be_table_266 a
,could_be_table_267 b
where x.change_id = a.change_id (+)
and x.change_id = b.change_id (+)
and x.change_notice = 'COM-10034'
Using column names like "REPORTING PERSON" rather than REPORTING_PERSON is just a pain in the …
What column headings one wants in a report/screen doesn’t have to drive the names of select list items in SQL.
TYPE is likely not a good name … reserved word -
Join a SELECT-Statement with a INDEX
can I force a SELECT-Statement to use a certain Table-INDEX?
f.e.
select * from table a
where a.key like '%p'
..forced index a.idx.--Yes. You can.
Use SQL hint.
select /*+ index (tablename indexname) */.
If the index is usable-Oracle will use it. If not -Oracle will see it as a remark. -
What is syntax for inner join of Select statement with Secondary Index
Hi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.PHi Genies,
Here i have created the Secondary index for table COEP and also used for select query but there is no improvement in runtime . taking same time for select query without index as well as with index. my code is
SELECT * INTO CORRESPONDING FIELDS OF TABLE ITAB_COEP FROM COEP AS A
INNER JOIN COBK AS B ON ( A~BELNR = B~BELNR AND A~KOKRS = B~KOKRS AND A~GJAHR = B~GJAHR )
WHERE A~OBJNR = OBJNR
AND A~GJAHR = CURRY
AND B~GJAHR = CURRY
AND A~RBEST = ''
AND A~BEKNZ = 'S'
AND B~BELNR NE WA_COBK-BELNR
AND B~AWREF_REV = ''
AND B~AWORG_REV = ''
AND B~KOKRS = WA_COIOB-KOKRS
AND B~BLDAT BETWEEN START_DATE AND END_DATE
AND B~BLART IN ('SA','KA','KR','AB') %_HINTS ORACLE 'INDEX("COEP" "COEP~ZBU")'.
index name is ZBU.
please any one let me know is there any syntax mistakes? but while checking and during the runtime it does'nt shows any error.
Regards,
Thangam.P -
Maximum number of joins in SELECT statement
Dear friends,
Can you tell me, how many max number of joins (inner & outer) we can make in ABAP.
For eg:
table 1: A B C fields
table 2: C D E fields
table 3: E F G fileds..............
Thanks in advance for your valuable time.
Best regards,
Satishhi,
no limit for joins[inner or outer ] in a table , when we consider performance issue joins will reduce the performance of our program so go views instead of joins.
with cheers,
suresh babu aluri. -
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 -
Adding one more table to the select statement joining 4 tables gives dump
Hi All,
There is a select statement using which four tables namely VBAK,VBAP,LIPS and LIKPUK(view) are joined(inner join).Here, date and time fields are selected from LIPS and used.
My requirement is to consider the Date (LIKP - WADAT_IST) instead of LIPS-ERDAT and time(LIKP-SPE_WAUHR_IST) is to be used instead of LIPS-erzet.
Neither LIPS nor LIKPUK contains time(SPE_WAUHR_IST) field. And, I cannot remove LIPS table or LIKPUK view as each contains a unique field which is used in the report.
When I tried to join LIPS in the select query, it is going to dump.
Can someone suggest a good approach ?
Thanks,
PavanThank you for the detailed explanation of the dump.
The dump details together with your code lead to the answer: 42.
Regards,
Clemens -
Joins And For all Enteries in Select Statement
Could you please tell me when there is a high amount of data which is being handled in the table, does the use of INNER JOINS and FOR ALL ENTERIES in SELECT Statement decreases the system performance? ?
Can you also let me know where can i get some tips regarding do's and dont's for ABAP Programming, I want to increase my system performance.
Currently the programs which are being used are taking a lot of time for execution...
Its very URGENT!Hai Jyotsna
Go through the following Tips for improving Performence
For all entries
The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
The plus
Large amount of data
Mixing processing and reading of data
Fast internal reprocessing of data
Fast
The Minus
Difficult to program/understand
Memory could be critical (use FREE or PACKAGE size)
Some steps that might make FOR ALL ENTRIES more efficient:
Removing duplicates from the driver table
Sorting the driver table
If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:
FOR ALL ENTRIES IN i_tab
WHERE mykey >= i_tab-low and
mykey <= i_tab-high.
Nested selects
The plus:
Small amount of data
Mixing processing and reading of data
Easy to code - and understand
The minus:
Large amount of data
when mixed processing isnt needed
Performance killer no. 1
Select using JOINS
The plus
Very large amount of data
Similar to Nested selects - when the accesses are planned by the programmer
In some cases the fastest
Not so memory critical
The minus
Very difficult to program/understand
Mixing processing and reading of data not possible
Use the selection criteria
SELECT * FROM SBOOK.
CHECK: SBOOK-CARRID = 'LH' AND
SBOOK-CONNID = '0400'.
ENDSELECT.
SELECT * FROM SBOOK
WHERE CARRID = 'LH' AND
CONNID = '0400'.
ENDSELECT.
Use the aggregated functions
C4A = '000'.
SELECT * FROM T100
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100-MSGNR > C4A.
C4A = T100-MSGNR.
ENDSELECT.
SELECT MAX( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = 'D' AND
ARBGB = '00'.
Select with view
SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T
WHERE DOMNAME = DD01L-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
SELECT * FROM DD01V
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
Select with index support
SELECT * FROM T100
WHERE ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
SELECT * FROM T002.
SELECT * FROM T100
WHERE SPRSL = T002-SPRAS
AND ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
ENDSELECT.
Select Into table
REFRESH X006.
SELECT * FROM T006 INTO X006.
APPEND X006.
ENDSELECT
SELECT * FROM T006 INTO TABLE X006.
Select with selection list
SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT
SELECT DOMNAME FROM DD01L
INTO DD01L-DOMNAME
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT
Key access to multiple lines
LOOP AT TAB.
CHECK TAB-K = KVAL.
ENDLOOP.
LOOP AT TAB WHERE K = KVAL.
ENDLOOP.
Copying internal tables
REFRESH TAB_DEST.
LOOP AT TAB_SRC INTO TAB_DEST.
APPEND TAB_DEST.
ENDLOOP.
TAB_DEST[] = TAB_SRC[].
Modifying a set of lines
LOOP AT TAB.
IF TAB-FLAG IS INITIAL.
TAB-FLAG = 'X'.
ENDIF.
MODIFY TAB.
ENDLOOP.
TAB-FLAG = 'X'.
MODIFY TAB TRANSPORTING FLAG
WHERE FLAG IS INITIAL.
Deleting a sequence of lines
DO 101 TIMES.
DELETE TAB_DEST INDEX 450.
ENDDO.
DELETE TAB_DEST FROM 450 TO 550.
Linear search vs. binary
READ TABLE TAB WITH KEY K = 'X'.
READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.
Comparison of internal tables
DESCRIBE TABLE: TAB1 LINES L1,
TAB2 LINES L2.
IF L1 <> L2.
TAB_DIFFERENT = 'X'.
ELSE.
TAB_DIFFERENT = SPACE.
LOOP
AT TAB1.
READ TABLE TAB2 INDEX SY-TABIX.
IF TAB1 <> TAB2.
TAB_DIFFERENT = 'X'. EXIT.
ENDIF.
ENDLOOP.
ENDIF.
IF TAB_DIFFERENT = SPACE.
ENDIF.
IF TAB1[] = TAB2[].
ENDIF.
Modify selected components
LOOP AT TAB.
TAB-DATE = SY-DATUM.
MODIFY TAB.
ENDLOOP.
WA-DATE = SY-DATUM.
LOOP AT TAB.
MODIFY TAB FROM WA TRANSPORTING DATE.
ENDLOOP.
Appending two internal tables
LOOP AT TAB_SRC.
APPEND TAB_SRC TO TAB_DEST.
ENDLOOP
APPEND LINES OF TAB_SRC TO TAB_DEST.
Deleting a set of lines
LOOP AT TAB_DEST WHERE K = KVAL.
DELETE TAB_DEST.
ENDLOOP
DELETE TAB_DEST WHERE K = KVAL.
Tools available in SAP to pin-point a performance problem
· The runtime analysis (SE30)
· SQL Trace (ST05)
· Tips and Tricks tool
· The performance database
Optimizing the load of the database
Using table buffering
Using buffered tables improves the performance considerably. Note that in some cases a statement can not be used with a buffered table, so when using these statements the buffer will be bypassed. These statements are:
Select DISTINCT
ORDER BY / GROUP BY / HAVING clause
Any WHERE clause that contains a sub query or IS NULL expression
JOIN s
A SELECT... FOR UPDATE
If you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to the SELECT clause.
Use the ABAP SORT Clause Instead of ORDER BY
The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The database server will usually be the bottleneck, so sometimes it is better to move the sort from the database server to the application server.
If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT statement to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the database server sort it.
Avoid the SELECT DISTINCT Statement
As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.
Thanks & regards
Sreenivasulu P -
How to join THREE different tables into internal table using one select statement .
How to join THREE different tables into internal table using one select statement .
Hi experts,
I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
Scenario:
Database tables:
SPFLI
SFLIGHT
SBOOK.
Table Fields:
SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
SEATSOCC_C SEATSMAX_F SEATSOCC_F
SBOOK - CARRID CONNID CLASS
MY INTERNAL TABLE IS IT_XX.
Your help much appreciated.
Thanks in advance.
Pawan.Hi Pawan,
please check below codes. hope it can help you.
TYPES: BEGIN OF ty_xx,
carrid TYPE spfli-carrid ,
connid TYPE spfli-connid ,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom ,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto ,
fldate TYPE sflight-fldate ,
seatsmax TYPE sflight-seatsmax ,
seatsocc TYPE sflight-seatsocc ,
seatsmax_b TYPE sflight-seatsmax_b,
seatsocc_b TYPE sflight-seatsocc_b,
seatsmax_f TYPE sflight-seatsmax_f,
seatsocc_f TYPE sflight-seatsocc_f,
class TYPE sbook-class,
END OF ty_xx,
t_xx TYPE STANDARD TABLE OF ty_xx.
DATA: it_xx TYPE t_xx.
SELECT spfli~carrid
spfli~connid
spfli~countryfr
spfli~cityfrom
spfli~countryto
spfli~cityto
sflight~fldate
sflight~seatsmax
sflight~seatsocc
sflight~seatsmax_b
sflight~seatsocc_b
sflight~seatsmax_f
sflight~seatsocc_f
sbook~class
INTO TABLE it_xx
FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid.
Thanks,
Yawa -
ABAP Joins or Separate select statements?
Hi,
I am working on a simulation of an implementation project as part of my in-house training programme. I am a rookie to ABAP and am now doing a print program that requires master data selection from tables ANLZ, LFA1, MSEG and CSKT, and also related line items from ANLA.
As a former Java/.NET programmer I used to play with database joins. Now since ABAP joins are much simpler to use, I take the best advantage of them. For instance, in this particular program, I fetched related data from ANLZ, ANLA, LFA1 and CSKT into one internal table using a single select statement with ABAP joins.
Now I happen to hear (in bits and pieces) that one should limit the use of nested joins to a certain extend. Instead, for the above program, I was advised to use 4 internal tables and to select data separately using FOR ALL ENTRIES. But in this case, we need to use 4 select statements, which means 4 database operations in place of just one.
From ABAP documentation, I read that we can link upto 24 tables in a single select statement using ABAP joins.
Can anyone clarify more about this? Which is high on performance?
Using a single select statement using joins
or
Using multiple selects -- FOR ALL ENTRIES?
Thanks and regards,
ArunHi Arun,
you keep reading in these forums that FOR ALL ENTRIES is more performant, but this is simply not true.
In your example, joining four tables for one DB operation is better than storing a lot of redundant data in internal tables just to perform four separate DB operations using FOR ALL ENTRIES.
Make sure you join the tables correctly, i.e. link dependent tables giving their full primary key.
FOR ALL ENTRIES can be used where effective join statements are not possible, e.g. when cluster tables are involved (like BSEG).
Cheers
Thomas
Edit: check this out too: Inner Join or For All Entries -
Inner Join for Dynamic Select statement
Hi All,
Can some one please help me in rewriting the below select statement where i have to remove the existing table1 by putting a dynamic table name which has the same table structure.
select a~zfield1
a~zfield2
from ztab1 as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
I am looking something as below. But encountering an error when using the below statement
select a~zfield1
a~zfield2
from (v_ztab1) as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
No Separate selects please. Please help me in rewriting the same select statement itself.
Regards,
PSKhi,
What error you are getting ?
Also INTO is missing from the statement.
SELECT pcarrid pconnid ffldate bbookid
INTO TABLE itab
FROM ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' .
thanks -
Outer Join (select) statement
hI
Im BW-Consultant. I have two tables with some fileds.
ZTABLE1 ---> MATNR, PRCTR, BUKRS, LIGNG, MATGR.And this table has 5-materials
ZTABLE2 --> MATNR, PRCTR, BUKRS, FKMNG, VERID. And this table has 10-materials.
These two tables(ZTABLE1, ZTABLE2) has 3-materials are common.
But i want all 15-materials in an another table ZTABLE3. So how can i write an <b>outer join statement.</b> .
Please give the OuterJoinCode(select statement) to get all 15-materials
regards
kumarExample
SELECT KNA1~KUNNR KNA1~ADRNR ADR6~SMTP_ADDR
INTO (A, B, C)
FROM KNA1 LEFT OUTER JOIN ADR6
ON KNA1~ADRNR = ADR6~ADDRNUMBER
WHERE KUNNR BETWEEN '0000000000' AND '0000500000'.
DATA: BEGIN OF wa,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH NON-UNIQUE KEY carrid.
SELECT s~carrid s~carrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON s~carrid = p~carrid AND
p~cityfrom = 'FRANKFURT'.
LOOP AT itab INTO wa.
WRITE: / wa-carrid, wa-carrname, wa-connid.
ENDLOOP.
A -
How to JOIN the results of multiple SELECT statements
Hello,
I currently have a table where each row represents a single census date for a given tag number, where each tag number can have multiple census dates and data which are represented by their own row in the table.
I currently have 2 SELECT statements that select all tag numbers given a census date, and would like to combine those 2 queries so that the data is presented in a manner such that for each tag number, instead of obtaining 2 rows for each tag number, I would be presented with 1 row for each tag number consisting of three columns: tag_number, data1, and data2.
Both of the requested dates are not necessarily present for all tag numbers, and in the event that only one date is present, the other column should contain null, but if both dates are not present for a given tag number, the tag number is omitted.
The two queries I would like to JOIN are:
SELECT a.tag_number, a.data AS data1
FROM tab1 a
WHERE
a.census_date='11/21/2009'and
SELECT b.tag_number, b.data AS data2
FROM tab2 b
WHERE
b.census_date='11/24/2009'The table from which I am selecting the data looks like such:
tag_number census_date data
1 11/21/2009 10
1 11/23/2009 11
1 11/24/2009 12
2 11/19/2009 13
2 11/21/2009 14And the data that I would like to result looks like:
tag_number data1 data2
1 10 12
2 14 nullAny help would be greatly appreciated.
Thank you in advance,
-Justin
Edited by: m8r-qbkka9 on Nov 24, 2009 4:17 PMHi,
This looks like a job for pivot
SELECT a.tag_number
, MAX (CASE WHEN a.census_date = TO_DATE ('11/21/2009'
'MM/DD/YYYY'
THEN a.data
END
) AS data1
, MAX (CASE WHEN a.census_date = TO_DATE ('11/24/2009'
'MM/DD/YYYY'
THEN a.data
END
) AS data2
FROM tab1 a
WHERE a.census_date IN ( TO_DATE ( '11/21/2009'
, 'MM/DD/YYYY'
, TO_DATE ( '11/21/2009'
, 'MM/DD/YYYY'
GROUP BY a.tag_number
;Comparing DATEs to stirngs, like '11/24/2009', is simply asking for trouble.
Always use a conversion function (like TO_DATE) or DATE literals instead. -
Select statement from a join file deletes the primary records with MS Expl.
Hello,
is reality,
Select statement from a join file deletes the primary records with MS Explorer 6, Firefox not, this with a normal data provider or with a normal "select..." statement.
This is very strange, I should have a.a.s.p. a solution or workaround
Thanks, Franco.
Message was edited by:
fbiaggiPlease see the following excerpt from the online documentation.
http://docs.oracle.com/cd/E11882_01/server.112/e22490/ldr_modes.htm#SUTIL1332
Enabled Constraints
During a direct path load, the constraints that remain enabled are as follows:
NOT NULL
UNIQUE
PRIMARY KEY (unique-constraints on not-null columns)
NOT NULL constraints are checked at column array build time. Any row that violates the NOT NULL constraint is rejected.
Even though UNIQUE constraints remain enabled during direct path loads, any rows that violate those constraints are loaded anyway (this is different than in conventional path in which such rows would be rejected). When indexes are rebuilt at the end of the direct path load, UNIQUE constraints are verified and if a violation is detected, then the index will be left in an Index Unusable state. See "Indexes Left in an Unusable State".
Maybe you are looking for
-
ITunes installs itself every time I open it.
Whenever I start iTunes, ever since upgrading to the latest version (10.1.1), Windows Installer comes up and installs iTunes. This lasts a few minutes and then iTunes finally comes up. Any help with this would be greatly appreciated.
-
Second HDD for a Probook 6570b
I want to know if I can replace the DVD unit with a HDD, and if possible please provide that PN for the tray to install the second HDD. I am planning to have the OS on a SSD and the data files on a standard HDD. Thanks
-
CENVAT account Match for FI or MM
hi... can any body tell me how we can match the CENVAT a/c for MM and FI? our balances in this GL r not match..pls tell me step by step how we can check it? regards Rekha sharma
-
Sporadic failure dng conversion
I've recently upgraded from Windows XP (SP3) to Windows 7 Ultimate 64 bit. At the same time I upgraded from 2 gb of RAM to 4 gb. Since the upgrade I've been experiencing random errors in DNG conversion. I usually convert to DNG inside Lightroom 2.5 b
-
Hi, I have created a hidden field on my jsp page and called the onsubmit method for the form hoping to pass this hidden field to my servlet. It keeps returning empty. Could someone look at my code and help me out? The on submit is calling a piece of