Retrive data from two tables into one internal table.
Hi SDN,
I am downloading the Assets data from two tables ANLA,ANLZ.
there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
can you please send me the SELECT Syntax for this probl.....
Thank you & Regards,
Manoj
Hi manoj,
Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
data: begin of itab occurs 0,
BUKRS like anla-BUKRS,
ANLN1 like anla-ANLN1,
BDATU like anlz-BDATU,
end of itab.
select anlabukrs anlaANLN1 anlzBDATU into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
Please come back for any clarification.
Thanks and Regards,
saurabh
Similar Messages
-
Hi ,
I have two tables, we want to retrive data from both the tables please see example below
Table 1
A B X Y Z
1 2
Table B
A B C
1 2 5
1 2 6
1 2 7
I want output like
A B C
1 2 5
Null Null 6
Null Null 7
Regards
Message was edited by:
rajib.sarkarCould you explain the logic behind that?
-
Retriving data from two tables at a time.
Please use this forum to provide feedback about OTN content/services. All other posts will be DELETED.
hi all,
Am using win98 and Oracle 7.
I have splitted a table into two tables having 10 and 9 fields respectively and records of 2000.Now in form builder I have put both tables in same block and on same canvas.
Now when I execute a query I retrieve records of 1st table and can navigate through records of 1st table only .To retrive records of 2nd table I have to put curser in 2nd table and query again for data retrival from 2nd table.This is bothering me to match coulmn of both tables.
Is there any way to execute the records of both tables at a time, so that matching coulmns of both tables would become easy to reach.
Thanks and Regardsheeeey mohammad
you have first to make master/detail block not one block only
then jion between them as pk and fk -
How to combine data from two rows into one row
I have the following sets of data. I want to find all the duplicate sets of field values. in the data below there is only one duplicate set: brenda, analyst, green.
DocID and Doc Seq combine to form the set key. FieldID I believe are consistent in that 1 is always name, 2 is job, 3 is favorite color etc. but there are up to 20 field IDs.
To tell you the truth, my client is a bit sketchy about the data and the values. I would like collapse the sets by getting all the field values into a single row. They could be in the same column, or in their own columns. This way I can then look for whatever
dups my customer seems to think that he has.
the first image is what i want (either in same column or in different columns. but they have to be in the order of the FieldID), the second is what i have. THANKSCREATE TABLE #t (
c1 INT NOT NULL PRIMARY KEY,
c2 VARCHAR(50) NOT NULL
GO
INSERT INTO #t(c1, c2) VALUES(1, 'P1,P2,P3')
INSERT INTO #t(c1, c2) VALUES(2, 'P2,P3')
GO
-- Generate set of numbers
-- Idea from Itzik Ben-Gan
;WITH
L0 AS (SELECT 1 AS n UNION ALL SELECT 1),
L1 AS (SELECT 1 AS n FROM L0 AS a, L0 AS b),
L2 AS (SELECT 1 AS n FROM L1 AS a, L1 AS b),
L3 AS (SELECT 1 AS n FROM L2 AS a, L2 AS b),
L4 AS (SELECT 1 AS n FROM L3 AS a, L3 AS b),
Numbers AS (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS Number FROM L4)
SELECT
t.c1,
t.c2,
SUBSTRING(',' + t.c2 + ',', Number + 1, CHARINDEX(',', ',' + t.c2 + ',',
Number + 1) - Number - 1) AS Item,
ROW_NUMBER() OVER(PARTITION BY t.c1 ORDER BY n.Number) AS rn
FROM
#t AS t, Numbers AS n
WHERE
n.Number <= LEN(t.c2)
AND SUBSTRING(',' + t.c2 + ',', n.Number, 1) = ','
ORDER BY
t.c1, rn
GO
DROP TABLE #t
GO
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Unable to retrive data from two tables using multiple joins
Hi,
Table: EMP mgr
eid name
eid mgrid
1
A 1
null
2
B 2
3
3
C 3
3
i need to get result as:
eid ename mgrname
thanks
AVSSai,
It would be very helpful if you could mention your table structures a bit more clearly. Would allow for effective replies from fellow users as well. :)
However, assuming that your structure would be as follows presenting the query as below:
DECLARE @Emp TABLE(Eid Int, ename Varchar(50))
DECLARE @Emp_Mgr TABLE(Eid int, mgrid int null )
INSERT INTO @Emp select 1,'Ram'
INSERT INTO @Emp select 2,'Shyam'
INSERT INTO @Emp_Mgr select 1,NULL
INSERT INTO @Emp_Mgr select 2,1
SELECT * FROM @Emp
SELECT * FROM @Emp_Mgr
Query to print results as EID, ENAME, MGRNAME
SELECT em.eid,e1.ename as ENAME,e2.ename as MGRNAME
FROM @Emp_Mgr em
JOIN @Emp e1 ON em.eid=e1.eid
JOIN @Emp e2 ON em.mgrid=e2.eid
However, as you see this approach of maintaining two tables for preserving the employee-manager data is redundant and makes the queries unnecessarily complex. So, you could opt for the widely used single table format as mentioned by Praveen as well. Check
if this helps you..
Recommended Structure
*Avoidance of redundant storage of data
*Lesser Joins in queries
DECLARE @Emp TABLE(Eid Int , Ename Varchar(50) , mgrid int null )
INSERT INTO @Emp(Eid , ename , mgrid) values(1 , 'Ram' , null) , (2 , 'Shyam' , 1)
SELECT * FROM @Emp
Query to print results as EID, ENAME, MGRNAME
SELECT e.Eid , e.Ename , m.Ename as MgrName
FROM @Emp e
JOIN @Emp m On a.mgrid = b.eid
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
How do I merge my Mail data from two Macs into one?
One is Lion and the other is Mountain Lion, both 27" iMacs. I have saved the Mail data from the Lion one and will reformat its HDD for a clean install of Mountain Lion. Then I plan to import a (CCC) clone of my newer iMac. I need to merge the mail because some mail items are missing on the clone that existed on the erased iMac.
Copy or move the song files from one account to a shared location and then drag them into the open iTunes window when logged into the other account.
(60844) -
Retrieve of data from two columns into one column
For eg: i have a data in a table with columns A & B of same size
A B
1 2
2
3 1
4 2
5 3
6 5
7 1
8 4
9
10 8
Through a select i want the output of my data in one single
columns, Well I can do this by using union.
But my output should be like
if I select by condition where A=2
my output should be
2
1
3
7
4
because all these numbers are linked with 2 how do i do this
because it is like searching the number 2 in two columns and wherever this number 2 is linked i should get all the data relevant to it.
Hope u got my point what i exactly want
Can anyone help me it is quite urgent.
Regards
Vamsi Mohani do not a concatenated data
i have a data in a table with columns A & B of same size
A B
1 2
2
3 1
4 2
5 3
6 5
7 1
8 4
9
10 8
if my where condition is 'where A=2'
my output should be
1
2
3
4
5
6
8
10
i want my query to search as loop so that it keeps on searching
for related data as in my case it is
2 is linked to 1
1 is linked to 3
3 is linked to 4
my query should keep on seaching for linked numbers till
it does not find any mathing linked numbers
and the resulted output should come in one single column -
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 -
How to extract data from info cube into an internal table using ABAP code
HI
Can Anyone plz suggest me
How to extract data from info cube into an internal table using ABAP code like BAPI's or function modules.
Thankx in advance
regds
AJAYHI Dinesh,
Thankq for ur reply
but i ahve already tried to use the function module.
When I try to Use the function module RSDRI_INFOPOV_READ
I get an information message "ERROR GENERATION TEST FRAME".
can U plz tell me what could be the problem
Bye
AJAY -
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 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 -
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. -
Selecting data from two tables
I am trying to select data from two tables. The only problem that I am running into, is that i am only seeing results from my 'uploads' table. there is also a record in documents where user = 1 that should show up. here is my sql:
$userIDNum = 1;
$sql="Select *
from uploads, documents
WHERE uploads.user = documents.user AND uploads.user = $userIDNum
ORDER BY uploads.title ASC, documents.title ASC";You'll need to explain a little more about your data and what you are trying to accomplish. Your current sql will select all columns from both the uploads and documents tables but only rows where the user id in both tables match, AND the user id equals 1. Is that not what you are seeing? Where's the code that outputs the results?
-
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 -
Retrive data from 4 tables without using joins
hi ,
i have to retrive data from 4 tables........but i donot want to use joins because of performance issues.
please guide me how to proceed further ?
thankshi manish,
CONSTANTS: c_act_plan(2) TYPE c VALUE 'U1' ,
c_person(1) TYPE c VALUE 'P' ,
p1_betid(8) TYPE c VALUE '50005316',
c_topdown(1) TYPE c VALUE 'A' ,
c_admnby(3) TYPE c VALUE '032' ,
c_bet_type(1) TYPE c VALUE 'Q' ,
c_firmed(1) TYPE c VALUE '1' ,
c_subtyp_mail(4) TYPE c VALUE '0001' .
TYPES: BEGIN OF ty_hrp1001,
objid TYPE hrp1001-objid,
END OF ty_hrp1001,
BEGIN OF ty_pa0001,
pernr TYPE pa0001-pernr,
subty TYPE pa0001-subty,
objps TYPE pa0001-objps,
sprps TYPE pa0001-sprps,
endda TYPE pa0001-endda,
begda TYPE pa0001-begda,
seqnr TYPE pa0001-seqnr,
werks TYPE pa0001-werks,
gsber TYPE pa0001-gsber,
btrtl TYPE pa0001-btrtl,
END OF ty_pa0001,
BEGIN OF ty_t500p,
persa TYPE t500p-persa,
name1 TYPE t500p-name1,
END OF ty_t500p,
BEGIN OF ty_t001p,
werks TYPE t001p-werks,
btrtl TYPE t001p-btrtl,
btext TYPE t001p-btext,
END OF ty_t001p,
BEGIN OF ty_pa0002,
pernr TYPE pa0002-pernr,
subty TYPE pa0002-subty,
objps TYPE pa0002-objps,
sprps TYPE pa0002-sprps,
endda TYPE pa0002-endda,
begda TYPE pa0002-begda,
seqnr TYPE pa0002-seqnr,
nachn TYPE pa0002-nachn,
vorna TYPE pa0002-vorna,
END OF ty_pa0002,
BEGIN OF ty_pa0105,
pernr TYPE pa0105-pernr ,
subty TYPE pa0105-subty ,
objps TYPE pa0105-objps ,
sprps TYPE pa0105-sprps ,
endda TYPE pa0105-endda ,
begda TYPE pa0105-begda ,
seqnr TYPE pa0105-seqnr ,
usrid_long TYPE pa0105-usrid_long,
END OF ty_pa0105,
BEGIN OF ty_output,
pernr TYPE pa0002-pernr ,
werks TYPE pa0001-werks ,
gsber TYPE pa0001-gsber ,
btrtl TYPE pa0001-btrtl ,
name1 TYPE t500p-name1 ,
btext TYPE t001p-btext ,
nachn TYPE pa0002-nachn ,
vorna TYPE pa0002-vorna ,
usrid_long TYPE pa0105-usrid_long,
END OF ty_output.
DATA: w_hrp1001 TYPE ty_hrp1001,
t_hrp1001 TYPE TABLE OF ty_hrp1001,
t_hrp1001_tmp TYPE TABLE OF ty_hrp1001,
w_pa0001 TYPE ty_pa0001 ,
t_pa0001 TYPE SORTED TABLE OF ty_pa0001
WITH NON-UNIQUE KEY pernr ,
t_pa0001_tmp TYPE TABLE OF ty_pa0001 ,
w_t500p TYPE ty_t500p ,
t_t500p TYPE HASHED TABLE OF ty_t500p
WITH UNIQUE KEY persa ,
w_t001p TYPE ty_t001p ,
t_t001p TYPE HASHED TABLE OF ty_t001p
WITH UNIQUE KEY werks btrtl ,
w_pa0002 TYPE ty_pa0002 ,
t_pa0002 TYPE SORTED TABLE OF ty_pa0002
WITH NON-UNIQUE KEY pernr ,
t_pa0002_tmp TYPE TABLE OF ty_pa0002 ,
w_pa0105 TYPE ty_pa0105 ,
t_pa0105 TYPE SORTED TABLE OF ty_pa0105
WITH NON-UNIQUE KEY pernr ,
w_output TYPE ty_output ,
t_output TYPE TABLE OF ty_output .
SELECT objid
FROM hrp1001
INTO TABLE t_hrp1001
WHERE otype EQ c_person
AND plvar EQ c_act_plan
AND rsign EQ c_topdown
AND relat EQ c_admnby
AND istat EQ c_firmed
AND begda LE sy-datum
AND endda GT sy-datum
AND sclas EQ c_bet_type
AND sobid EQ p1_betid.
IF sy-subrc EQ 0.
SORT t_hrp1001 BY objid.
ENDIF.
IF NOT t_hrp1001[] IS INITIAL.
t_hrp1001_tmp[] = t_hrp1001[].
DELETE ADJACENT DUPLICATES FROM t_hrp1001_tmp
COMPARING objid.
SELECT pernr
subty
objps
sprps
endda
begda
seqnr
werks
gsber
btrtl
FROM pa0001
INTO TABLE t_pa0001
FOR ALL ENTRIES IN t_hrp1001_tmp
WHERE pernr EQ t_hrp1001_tmp-objid
AND endda GT sy-datum
AND begda LE sy-datum.
SELECT pernr
subty
objps
sprps
endda
begda
seqnr
nachn
vorna
FROM pa0002
INTO TABLE t_pa0002
FOR ALL ENTRIES IN t_hrp1001_tmp
WHERE pernr EQ t_hrp1001_tmp-objid
AND endda GT sy-datum
AND begda LE sy-datum.
ENDIF.
IF NOT t_pa0001[] IS INITIAL.
t_pa0001_tmp[] = t_pa0001[].
SORT t_pa0001_tmp BY werks btrtl.
DELETE ADJACENT DUPLICATES FROM t_pa0001_tmp COMPARING werks btrtl.
SELECT werks
btrtl
btext
FROM t001p
INTO TABLE t_t001p
FOR ALL ENTRIES IN t_pa0001_tmp
WHERE werks EQ t_pa0001_tmp-werks
AND btrtl EQ t_pa0001_tmp-btrtl.
DELETE ADJACENT DUPLICATES FROM t_pa0001_tmp COMPARING werks.
SELECT persa
name1
FROM t500p
INTO TABLE t_t500p
FOR ALL ENTRIES IN t_pa0001_tmp
WHERE persa EQ t_pa0001_tmp-werks.
ENDIF.
IF NOT t_pa0002[] IS INITIAL.
t_pa0002_tmp[] = t_pa0002[].
DELETE ADJACENT DUPLICATES FROM t_pa0002_tmp COMPARING pernr.
SELECT pernr
subty
objps
sprps
endda
begda
seqnr
usrid_long
FROM pa0105
INTO TABLE t_pa0105
FOR ALL ENTRIES IN t_pa0002_tmp
WHERE pernr EQ t_pa0002_tmp-pernr
AND subty EQ c_subtyp_mail
AND endda GT sy-datum
AND begda LE sy-datum
AND usrty EQ c_subtyp_mail.
ENDIF.
REFRESH t_output.
LOOP AT t_hrp1001 INTO w_hrp1001.
LOOP AT t_pa0001 INTO w_pa0001
WHERE pernr EQ w_hrp1001-objid.
READ TABLE t_t500p INTO w_t500p WITH KEY persa = w_pa0001-werks
TRANSPORTING
name1.
CHECK sy-subrc EQ 0.
READ TABLE t_t001p INTO w_t001p WITH KEY werks = w_pa0001-werks
btrtl = w_pa0001-btrtl
TRANSPORTING
btext.
LOOP AT t_pa0002 INTO w_pa0002
WHERE pernr EQ w_hrp1001-objid.
LOOP AT t_pa0105 INTO w_pa0105
WHERE pernr EQ w_pa0002-pernr.
w_output-pernr = w_pa0002-pernr .
w_output-werks = w_pa0001-werks .
w_output-gsber = w_pa0001-gsber .
w_output-btrtl = w_pa0001-btrtl .
w_output-name1 = w_t500p-name1 .
w_output-btext = w_t001p-btext .
w_output-nachn = w_pa0002-nachn .
w_output-vorna = w_pa0002-vorna .
w_output-usrid_long = w_pa0105-usrid_long.
APPEND w_output TO t_output.
CLEAR w_output.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
Reward if usful,
Thanks,
Srikanth.A
Maybe you are looking for
-
I am a new ipod touch user. I have my ipod connected to my computer, but when I try and get into anything it says I am not connected to the internet. Please help a newbee????
-
InDesign cross-document Text Anchor Hyperlinks
I'm combining several InDesign files into one PDF, with several hundred text links across the different sections, as well as within each. The cross-document (section) Text Anchor Hyperlinks work fine in my workspace - but when I change the file locat
-
Retrieving password for Time Machine
Hi all! For some time now, when I turn my computer on I get a pop up window asking me to log onto my Time Machine so my iMac can back up to it. The time Machine window has my name in it but every password I try does not work. I can see where you can
-
hi !!!!!!!!!!!! Im using a SAX parser to parse an xml file im successful in doing it i got tit parse after parising i want the value of a particular tag for example i have a tag as <filtername>datasource</filtername> i want datasource after parsing t
-
Hi Sorry this is a really simple question, and its probably been answered a thousand time I have Early 2011 13" MBP and im unsure as to how to connect it to an external monitor. Am i able to use the thunderport port, in conjuction with any of these a