Fetching data from two tables
Hi friends,
I've two similar tables A and B with one more column in table B that is "Active Flag".
Table A
Rowid----Fname----Lname
101-----AF1----------AL1
102----AF2-----------AL2
103-----AF3---------AL3
104-----AF4---------AL4
Table B
Rowid-----Fname---Lname---Flag
101-----BF1----------BL1--------Y
102-----BF2----------BL2---------N
103-----BF3----------BL3--------N
104-----BF4----------BL4-------Y
I need to fetch data in Table C with column rowid, Fname and Lname.
If Flag is Y in Table B, this record should come to table C otherwise the record from table A will come to C. Rowid is the primary key.
Table C should be like this..
Rowid-----Fname---Lname
101-----BF1----------BL1
102-----AF2----------AL2
103-----AF3----------AL3
104-----BF4----------BL4
Thanks in advance
Hi,
try this
QL> With T As
2 (
3 Select 101 Id, 'BF1' fname, 'BL1' lname, 'Y' flag
4 From DUAL
5 Union All
6 Select 102, 'BF2', 'BL2', 'N'
7 From DUAL
8 Union All
9 Select 103, 'BF3', 'BL3', 'N'
10 From DUAL
11 Union All
12 Select 104, 'BF4', 'BL4', 'Y'
13 From DUAL),
14 T1 As
15 (
16 Select 101 Id, 'BF1' fname, 'BL1' lname
17 From DUAL
18 Union All
19 Select 102, 'AF2', 'AL2'
20 From DUAL
21 Union All
22 Select 103, 'AF3', 'AL3'
23 From DUAL
24 Union All
25 Select 104, 'BF4', 'BL4'
26 From DUAL)
27 Select T1.Id, T1.fname, T1.lname
28 From T, T1
29 Where T.Id = T1.Id
30 And T.flag='Y'
31 /
ID FNA LNA
101 BF1 BL1
104 BF4 BL4and rowid is oracle reserved word. you should be aware of oracle reserved word, kindly refer this v$reserved_words
Edited by: user291283 on Sep 7, 2009 10:18 PM
Similar Messages
-
Fetch data from two tables and insert into one table
I have similar to the following data in two tables (@Plant, @PlantDirector) and need to consolidate into one table (@PlantNew) as follows.
DECLARE @Plant TABLE (PlantID INT, PlantName VARCHAR(100))
INSERT INTO @Plant (PlantID, PlantName) VALUES (1, 'Name One'),(2, 'Name Two'),(3, 'Name Three'),(4, 'Name Four'),(5, 'Name Five'),(6, 'Name Six')
Director data for the Plants exist in the following table. Assistant value 1 means Assistant Director and 0 means Director.
Data exists only for subset of plants and a Plant may have one or both roles.
DECLARE @PlantDirector TABLE (PlantID INT, PlantDirectorID INT, Assistant bit)
INSERT INTO @PlantDirector (PlantID, PlantDirectorID, Assistant) VALUES (2, 111, 1),(2, 222, 0),(4, 333, 0),(6,444,1)
The above data needs to be inserted into one table (@PlantNew) as follows:
PlantID in @Plant table is IDENTITY value and needs to be inserted as-is into this table.
PlantDirExists will get a value of 1 if at least one record exists in @PlantDirector table for a PlantID. PlantAssistantDirID and PlantDirID should be set to the corresponding PlantDirID or NULL appropriately depending on the data.
DECLARE @PlantNew TABLE (PlantID INT, PlantName VARCHAR(100), PlantDirExists bit, PlantAssistantDirID INT, PlantDirID INT)
INSERT INTO @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
VALUES (1, 'Name One', 0, NULL, NULL),(2, 'Name Two', 1, 111, 222),(3, 'Name Three', 0, NULL, NULL),(4, 'Name Four', 1, NULL, 333),(5, 'Name Five', 0, NULL, NULL),(6, 'Name Six',1, 444, NULL)
How do I achieve the above using SQL ? Thanks.like this
INSERT @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
SELECT p.PlantID,
p.PlantName,
CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
PlantAssistantDirID,
PlantDirID
FROM @Plant p
LEFT JOIN (SELECT PlantID,
MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
@PlantDirector
GROUP BY PlantID)pd
ON pd.PlantID = p.PlantID
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
You're missing a FROM
insert into @PlantNew
SELECT p.PlantID,
p.PlantName,
CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
PlantAssistantDirID,
PlantDirID
FROM @Plant p
LEFT JOIN (SELECT PlantID,
MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
from @PlantDirector
GROUP BY PlantID)pd
ON pd.PlantID = p.PlantID -
I want to fetch data from two tables which are in two separate database. Is it possible to fetch similar from two schemas of same database.
Pls help with query.Hi,
Say you have two schema S1 and S2 in the same database 'xyz' then you can create two database links to these two schemas from any third schema as ::
CREATE database link s1link connect to S1 identified by <password of S1> using 'xyz' ;
CREATE database link s2link connect to S2 identified by <password of S2> using 'xyz' ;
Now say if there is a table called tab1 in schema S1, then you can get data from it as ::
SELECT T1.*
FROM tab1@s1link T1
WHERE < you can put conditions here> ;
Similarly for the columns of a table of schema S2.
- Thanks
Sandipan -
Fetch the data from two tables
hell all
i want to fetch the data from two tables, one is from internal table and another one is data base table. what syntax i have to use either FOR ALL ENTRIES or INNER JOIN?hi
Use FOR ALL ENTRIES.
see the sample code
select * into table tvbrk from vbrk
where fkart in ('F2', 'F3', 'RE',
'ZVEC' , 'ZVEM' , 'ZVED',
'S1')
and erdat in so_erdat
and kunag in s_kunag.
erdat in so_erdat
and fkart in ('F2', 'F3', 'RE',
'ZVEC' , 'ZVEM').
if not tvbrk is initial.
select * into table t_zregion from zregion
for all entries in tvbrk
where country = tvbrk-land1
and region = s_regio.
endif.
thanks
sitaram -
SQL Select Performance - Approached to fetch data from big table
Hi
I just wanted to know view on different approached to fetch data from a table which has 40 billion records and which joined to another table which has 1 million record.
e.g.
I have two tables TableA and TableB
TableA has 40 Billion records has 6 columns
TableA has partitions on Date
TableA has required indexes
TableB has 1 Milluion record and has 10 columns
Table A has indexes
Now I have written query like
select distinct TableA.column1,TableA.column2,TableB.columnA
FROM TableA join TableB
ON TableA.Column1=TableB.Column2
WHERE TableA.DateColumn between StartDate and EndDate
for a given date range it will fetch 5 billion of records which takes around 40 minutes.
I just wanted to know what all tuning approaches I can follow. What would be the best approach to make record retrieval faster in such a scenario.
Just wanted to know your vies/experience in such a scenarioSufficiently large array fetchsize
and,
possibly using parallel query,
pop into my mind.
I would be interested though in the business requirement that asks for you to write a program that gets 5 billion (!) rows out of the database... -
Populate ADF Rich Table taking data from two tables of database
Hi,
Can anyone please guide me as to how I can populate ADF Rich Table taking data from two tables A and B of a database.
The condition is
I want to fetch row 1 from table A and populate into ADF Rich Table at row 1
then
I want to fetch row 1 from table B and populate into ADF Rich Table at row 2
and so on....
Many thanks for your help..
Regards,
RohitThe better place where you will learn:
http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/bcquerying.htm -
Select query taking too much time to fetch data from pool table a005
Dear all,
I am using 2 pool table a005 and a006 in my program. I am using select query to fetch data from these table. i.e. example is mentioned below.
select * from a005 into table t_a005 for all entries in it_itab
where vkorg in s_vkorg
and matnr in s_matnr
and aplp in s_aplp
and kmunh = it_itab-kmunh.
here i can't create index also as tables are pool table...If there is any solutions , than please help me for same..
Thanks ,it would be helpful to know what other fields are in the internal table you are using for the FOR ALL ENTRIES.
In general, you should code the order of your fields in the select in the same order as they appear in the database. If you do not have the top key field, then the entire database is read. If it's large then it's going to take a lot of time. The more key fields from the beginning of the structure that you can supply at faster the retrieval.
Regards,
Brent -
Generic datasource by function module to fetch data from multiple tables?
I'm writing a function module to fetch price, for generic datasource.
At first, extract test is OK. But InfoPackage never stop when loading data to PSA in BW.
And I find the example codes:
OPEN CURSOR WITH HOLD S_CURSOR FOR
SELECT (S_S_IF-T_FIELDS) FROM SFLIGHT
WHERE CARRID IN L_R_CARRID AND
CONNID IN L_R_CONNID.
ENDIF. "First data package ?
* Fetch records into interface table.
* named E_T_'Name of extract structure'.
FETCH NEXT CURSOR S_CURSOR
APPENDING CORRESPONDING FIELDS
OF TABLE E_T_DATA
PACKAGE SIZE S_S_IF-MAXSIZE.
IF SY-SUBRC <> 0.
CLOSE CURSOR S_CURSOR.
RAISE NO_MORE_DATA.
ENDIF.
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
ENDIF.
There using Cursor to fetch data package by package, and raise exception NO_MORE_DATA to stop the loading process.
Now I fetch data from multiple tables, I don't think I can use Cursor.
Then How can I handle this?
Thanks a lot.Thanks
IF IT_999[] IS INITIAL.
SELECT A~KNUMH A~MATNR A~KSCHL VKORG VTWEG A~DATBI A~DATAB KBETR KMEIN KPEIN C~MTART APPENDING CORRESPONDING FIELDS OF
TABLE TP_DATA
FROM A999 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
INNER JOIN MARA AS C
ON A~MATNR = C~MATNR
* FOR ALL ENTRIES IN IT_999
WHERE
* A~KNUMH = IT_999-KNUMH AND
( ( A~KSCHL = 'ZPRC' AND VKORG = 'Z000' AND VTWEG = 'Z1' ) OR
( A~KSCHL = 'ZPRD' AND VKORG = 'A000' AND VTWEG = 'Y3' ) ) AND
* A~DATBI >= SY-DATUM AND
LOEVM_KO = ''.
SELECT A~KNUMH A~MATNR A~KSCHL VKORG VTWEG A~DATBI A~DATAB KBETR AS KHETR KMEIN KPEIN C~MTART APPENDING CORRESPONDING FIELDS OF
TABLE TP_DATA
FROM A999 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
INNER JOIN MARA AS C
ON A~MATNR = C~MATNR
* FOR ALL ENTRIES IN IT_999
WHERE
* A~KNUMH = IT_999-KNUMH AND
A~KSCHL = 'ZPR3' AND A~VKORG = 'I000' AND
* DATBI >= SY-DATUM AND
LOEVM_KO = ''.
ENDIF.
IF IT_997[] IS INITIAL.
SELECT A~KNUMH A~MATNR A~KSCHL VTWEG A~DATBI A~DATAB KBETR AS KHETR KMEIN KPEIN C~MTART APPENDING CORRESPONDING FIELDS OF
TABLE TP_DATA
FROM A997 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
INNER JOIN MARA AS C
ON A~MATNR = C~MATNR
* FOR ALL ENTRIES IN IT_997
WHERE
* A~KNUMH = IT_997-KNUMH AND
A~KSCHL = 'ZPRA' AND VTWEG = 'Y1' AND
* DATBI >= SY-DATUM AND
LOEVM_KO = ''.
ENDIF.
IF IT_996[] IS INITIAL.
SELECT A~KNUMH A~MATNR A~KSCHL A~DATBI A~DATAB KBETR AS KHETR KMEIN KPEIN C~MTART APPENDING CORRESPONDING FIELDS OF
TABLE TP_DATA
FROM A996 AS A
INNER JOIN KONP AS B
ON A~KNUMH = B~KNUMH
INNER JOIN MARA AS C
ON A~MATNR = C~MATNR
* FOR ALL ENTRIES IN IT_996
WHERE
* A~KNUMH = IT_996-KNUMH AND
A~KSCHL = 'ZPRB' AND
* DATBI >= SY-DATUM AND
LOEVM_KO = ''.
ENDIF.
SELECT MATNR "u7269u6599u53F7u7801
MEINH "u4ED3u50A8u5355u4F4Du7684u5907u7528u8BA1u91CFu5355u4F4D
UMREZ "u57FAu672Cu8BA1u91CFu5355u4F4Du8F6Cu6362u5206u5B50
UMREN "u8F6Cu6362u4E3Au57FAu672Cu8BA1u91CFu5355u4F4Du7684u5206u6BCD
FROM MARM
INTO CORRESPONDING FIELDS OF TABLE IT_MARM
FOR ALL ENTRIES IN TP_DATA
WHERE MATNR = TP_DATA-MATNR AND MEINH = TP_DATA-KMEIN.
LOOP AT TP_DATA.
IF TP_DATA-KPEIN NE 0.
TP_DATA-KBETR = TP_DATA-KBETR / TP_DATA-KPEIN.
TP_DATA-KHETR = TP_DATA-KHETR / TP_DATA-KPEIN.
ENDIF.
IF TP_DATA-KSCHL = 'ZPRA'.
* TP_DATA-MEINH = 'ZI'.
* TP_DATA-KSCHL = 'B4'.
IF TP_DATA-KMEIN = 'ZI'.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ELSE.
READ TABLE IT_MARM INTO WA_MARM1 WITH KEY MATNR = TP_DATA-MATNR MEINH = TP_DATA-KMEIN.
* READ TABLE IT_MARM INTO WA_MARM2 WITH KEY MATNR = TP_DATA-MATNR MEINH = 'CT'.
TP_DATA-KHETR = TP_DATA-KHETR * WA_MARM1-UMREN / WA_MARM1-UMREZ.
* * WA_MARM2-UMREZ / WA_MARM2-UMREN.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ENDIF.
ELSEIF TP_DATA-KSCHL = 'ZPRB'.
* TP_DATA-KSCHL = 'L0'.
* TP_DATA-MEINH = 'ZI'.
IF TP_DATA-KMEIN = 'ZI'.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ELSE.
READ TABLE IT_MARM INTO WA_MARM1 WITH KEY MATNR = TP_DATA-MATNR MEINH = TP_DATA-KMEIN.
* READ TABLE IT_MARM INTO WA_MARM2 WITH KEY MATNR = TP_DATA-MATNR MEINH = 'BAG'.
TP_DATA-KHETR = TP_DATA-KHETR * WA_MARM1-UMREN / WA_MARM1-UMREZ.
* * WA_MARM2-UMREZ / WA_MARM2-UMREN.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ENDIF.
ELSEIF TP_DATA-KSCHL = 'ZPRC' OR TP_DATA-KSCHL = 'ZPRD'.
* TP_DATA-MEINH = 'ZI'.
IF TP_DATA-KMEIN = 'ZI'.
TP_DATA-KHETR = TP_DATA-KBETR * '1.17'.
ELSE.
READ TABLE IT_MARM INTO WA_MARM1 WITH KEY MATNR = TP_DATA-MATNR MEINH = TP_DATA-KMEIN.
* READ TABLE IT_MARM INTO WA_MARM2 WITH KEY MATNR = TP_DATA-MATNR MEINH = 'WZI'.
TP_DATA-KBETR = TP_DATA-KBETR * WA_MARM1-UMREN / WA_MARM1-UMREZ.
* * WA_MARM2-UMREZ / WA_MARM2-UMREN.
TP_DATA-KHETR = TP_DATA-KBETR * '1.17'.
ENDIF.
ELSEIF TP_DATA-KSCHL = 'ZPR3'.
* TP_DATA-KSCHL = 'B2'.
IF TP_DATA-KMEIN = 'ZI'.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ELSE.
READ TABLE IT_MARM INTO WA_MARM1 WITH KEY MATNR = TP_DATA-MATNR MEINH = TP_DATA-KMEIN.
* READ TABLE IT_MARM INTO WA_MARM2 WITH KEY MATNR = TP_DATA-MATNR MEINH = 'BAG'.
TP_DATA-KHETR = TP_DATA-KHETR * WA_MARM1-UMREN / WA_MARM1-UMREZ.
* * WA_MARM2-UMREZ / WA_MARM2-UMREN.
TP_DATA-KBETR = TP_DATA-KHETR / '1.17'.
ENDIF.
ENDIF.
TP_DATA-MEINH = '01'.
MODIFY TP_DATA.
E_T_DATA-MATNR = TP_DATA-MATNR.
E_T_DATA-KSCHL = TP_DATA-KSCHL.
E_T_DATA-KHETR = TP_DATA-KHETR.
E_T_DATA-KBETR = TP_DATA-KBETR.
E_T_DATA-KMEIN = TP_DATA-KMEIN.
E_T_DATA-DATAB = TP_DATA-DATAB.
E_T_DATA-DATBI = TP_DATA-DATBI.
APPEND E_T_DATA.
CLEAR WA_MARM1.
CLEAR WA_MARM2.
ENDLOOP.
Edited by: Shen Peng on Oct 20, 2010 10:09 AM -
To Select the data from two table one is transp table and onther is cluster
Hi All,
I want to select the data from two tables
Here i am giving with an example.
Fileds: kunnr belnr from bseg. table bseg
fields: adrnr from kna1 table: kna1.
Know i want to put these into one internal table based on kunnr and belnr.
Thanks in advance.
RameshHi,
U cant use joins on cluster table and BSEG is a cluster table so use FOR ALL ENTRIES for taht
refer this code
*& Form sub_read_bsak
text
--> p1 text
<-- p2 text
FORM sub_read_bsak.
*--Select data from BSAK Table
SELECT lifnr
augdt
augbl
gjahr
belnr
xblnr
blart
dmbtr
mwskz
mwsts
sgtxt
FROM bsak
INTO CORRESPONDING FIELDS OF TABLE it_bsak
WHERE belnr IN s_belnr
AND augdt IN s_augdt.
IF sy-subrc EQ 0.
*--Sort table by accounting document and vendor number
SORT it_bsak BY belnr lifnr.
ENDIF.
ENDFORM. " sub_read_bsak
*& Form sub_read_bseg
text
--> p1 text
<-- p2 text
FORM sub_read_bseg.
IF NOT it_bsak[] IS INITIAL.
*--Select data from BSEG table
SELECT belnr
gjahr
shkzg
kostl
hkont
ebeln
ebelp
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE it_bseg
FOR ALL ENTRIES IN it_bsak
WHERE belnr EQ it_bsak-belnr
AND gjahr EQ it_bsak-gjahr
AND shkzg EQ 'S'.
IF sy-subrc EQ 0.
*--Sort table by accounting document
SORT it_bseg BY belnr.
ENDIF.
ENDIF.
ENDFORM. " sub_read_bseg -
SELECT is taking lot of time to fetch data from cluster table BSET
<Modified the subject line>
Hi experts,
I want to fetch data of some fields from bset table but it is taking a lot of time as the table is cluster table.
Can you please suggest me any other process to fetch data from cluster table. I am using native sql to fetch data.
Regards,
SURYA
Edited by: Suhas Saha on Jun 29, 2011 1:51 PMHi Subhas,
As per your suggestion I am now using normal SQL statement to select data from BSET but it is still taking much time.
My SQL statement is :
SELECT BELNR
GJAHR
BUZEI
MWSKZ
HWBAS
KSCHL
KNUMH FROM BSET INTO CORRESPONDING FIELDS OF TABLE IT_BSET
FOR ALL ENTRIES IN IT_BKPF
WHERE BELNR = IT_BKPF-BELNR
AND BUKRS = IT_BKPF-BUKRS.
<Added code tags>
Can you suggest me anymore?
Regards,
SURYA
Edited by: Suhas Saha on Jun 29, 2011 4:16 PM -
How to use for all entires clause while fetching data from archived tables
How to use for all entires clause while fetching data from archived tables using the FM
/PBS/SELECT_INTO_TABLE' .
I need to fetch data from an Archived table for all the entries in an internal table.
Kindly provide some inputs for the same.
thanks n Regards
RameshHi Ramesh,
I have a query regarding accessing archived data through PBS.
I have archived SAP FI data ( Object FI_DOCUMNT) using SAP standard process through TCODE : SARA.
Now please tell me can I acees this archived data through the PBS add on FM : '/PBS/SELECT_INTO_TABLE'.
Do I need to do something else to access data archived through SAP standard process ot not ? If yes, then please tell me as I am not able to get the data using the above FM.
The call to the above FM is as follows :
CALL FUNCTION '/PBS/SELECT_INTO_TABLE'
EXPORTING
archiv = 'CFI'
OPTION = ''
tabname = 'BKPF'
SCHL1_NAME = 'BELNR'
SCHL1_VON = belnr-low
SCHL1_BIS = belnr-low
SCHL2_NAME = 'GJAHR'
SCHL2_VON = GJAHR-LOW
SCHL2_BIS = GJAHR-LOW
SCHL3_NAME = 'BUKRS'
SCHL3_VON = bukrs-low
SCHL3_BIS = bukrs-low
SCHL4_NAME =
SCHL4_VON =
SCHL4_BIS =
CLR_ITAB = 'X'
MAX_ZAHL =
tables
i_tabelle = t_bkpf
SCHL1_IN =
SCHL2_IN =
SCHL3_IN =
SCHL4_IN =
EXCEPTIONS
EOF = 1
OTHERS = 2
OTHERS = 3
It gives me the following error :
Index for table not supported ! BKPF BELNR.
Please help ASAP.
Thnaks and Regards
Gurpreet Singh -
How can we improve the performance while fetching data from RESB table.
Hi All,
Can any bosy suggest me the right way to improve the performance while fetching data from RESB table. Below is the select statement.
SELECT aufnr posnr roms1 roanz
INTO (itab-aufnr, itab-pposnr, itab-roms1, itab-roanz)
FROM resb
WHERE kdauf = p_vbeln
AND ablad = itab-sposnr+2.
Here I am using 'KDAUF' & 'ABLAD' in condition. Can we use secondary index for improving the performance in this case.
Regards,
HimanshuHi ,
Declare intenal table with only those four fields.
and try the beloe code....
SELECT aufnr posnr roms1 roanz
INTO table itab
FROM resb
WHERE kdauf = p_vbeln
AND ablad = itab-sposnr+2.
yes, you can also use secondary index for improving the performance in this case.
Regards,
Anand .
Reward if it is useful.... -
Cartesian of data from two tables with no matching columns
Hello,
I was wondering – what’s the best way to create a Cartesian of data from two tables with no matching columns in such a way, so that there will be only a single SQL query generated?
I am thinking about something like:
for $COUNTRY in ns0: COUNTRY ()
for $PROD in ns1:PROD()
return <Results>
<COUNTRY> {fn:data($COUNTRY/COUNTRY_NAME)} </COUNTRY>
<PROD> {fn:data($PROD/PROD_NAME)} </PROD>
</Results>
And the expected result is combination of all COUNTRY_NAMEs with all PROD_NAMEs.
What I’ve noticed when checking query plan is that DSP will execute two queries to have the results – one for COUNTRY_NAME and another one for PROD_NAME. Which in general results in not the best performance ;-)
What I’ve noticed also is that when I add something like:
where COUNTRY_NAME != PROD_NAME
everything is ok and there is only one query created (it's red in the Query plan, but still it's ok from my pov). Still it looks to me more like a workaround, not a real best approach. I may be wrong though...
So the question is – what’s the suggested approach for such queries?
Thanks,
Leszek
Edited by xnts at 11/19/2007 10:54 AMWhich in general results in not the best performanceI disagree. Only for two tables with very few rows, would a single sql statement give better performance.
Suppose there are 10,000 rows in each table - the cross-product will result in 100 million rows. Sounds like a bad idea. For this reason, DSP will not push a cross-product to a database. It will get the rows from each table in separate sql statements (retrieving only 20,000 rows) and then produce the cross-product itself.
If you want to execute sql with cross-products, you can create a sql-statement based dataservice. I recommend against doing so. -
Select data from two tables...!
HI Experts...!
i m a beginner user and i want to select data from two tables proj and prps.....using joins.....and internal tables i have written a code...
SELECT prps~pspnr
prps~objnr
prps~psphi
proj~ernam
proj~erdat
proj~pspnr
INTO table itab -
itab is internal table
FROM prps inner join proj
WHERE pspnr in p_no and prpspsphi = projpspnr.
but there is error in from clause ..please help me....
Advance thanx....Hi,
check the sample code bellow above two reply will solve out your problem but one more extra line in your code pointed out bellow.
TABLES: prps, proj.
TYPES: BEGIN OF ty_test,
pspnr LIKE prps-pspnr,
objnr LIKE prps-objnr,
psphi LIKE prps-psphi,
ernam LIKE proj-ernam,
erdat LIKE proj-erdat,
END OF ty_test.
DATA: itab TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
SELECT-OPTIONS: p_no FOR prps-pspnr.
SELECT prps~pspnr
prps~objnr
prps~psphi
proj~ernam
proj~erdat
* proj~pspnr " No need for this you have selected this in
* the first line because it is commone so you only need to select from any one
INTO TABLE itab
FROM prps INNER JOIN proj ON ( prps~pspnr = proj~pspnr )
WHERE prps~pspnr IN p_no.
Best Regards,
Faisal
Edited by: Rob Burbank on Dec 24, 2009 12:24 PM -
Fetch data from 3 tables (join vs select)
hi all...
i have to fetch data from three tables having one field common.
should i go with join or using three select statements..
which one is better.. plz clarify..
thanks in advance.
regards.Hi,
Use for all entries, what are the tables...
select field1
field2
from table
into table itab.
if sy-subrc = 0. "this is must ot table initial check
select field2
field3
from table2
for all entries in itab
into table itab2
where field2 = itab-field2.
select field2
field5
from table3
for all entries in itab
into table itab3
where field2 = itab-field2.
endif.
Maybe you are looking for
-
Using my Macbook Pro as an 'extended display' (2ndary monitor) to my G5
My G5 tower looks like it has two DVI connections: one is (30+5) pins and the other is (24+5) pins. I have a simple ViewSonic monitor connected to this G5 using the (24+5) pins. I am trying to use my new Macbook Pro as a secondary monitor (extended d
-
It is beginning to shutdown with no warning more frequently. What can I do to locate the exact issue? My warranty has expired so I would like to get to the bottom of it without taking it in to an apple store. I am currently learning how to do diagnos
-
After updating my iphone4s to the Ois7 my phone is now diabled how do I enable it?
How do I re-enable my iphone 4s after updating to iOs7?
-
I was upgrading my iTunes program last night, but there was an error in the installation. Runtime error of incorrectly installing of C+ by the program. Now I can not access my iTunes program. Is there a fix to this problem?
-
Hi, Can any pne tell me the BAPI for Network Activity. I have to pass the below listed fields. PROFID AUART DISPO WERKS AUFNR KTEXT GLTRP GLTRP PRONR PROJN PRCTR VORNR LTXA1 STEUS PROJN ARBID ARBEI ARBEH LARNT DAUNO SAKTO PRKST WAERS EKORG EKGRP MATK