cancel
Showing results for 
Search instead for 
Did you mean: 

fetch data from 3 tables (join vs select)

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

former_member188685
Active Contributor
0 Kudos

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.

Answers (8)

Answers (8)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Use select statement.That will be better.

select * from tab1 into table itab1.

select * from tab2 into table itab2 for all entries in itab1 where field1 = itab1-field1.

select * from tab3 into table itab3 for all entries in itab1 where field1 = itab1-field1.

Use loops to combine the fields into common itab.

KIndly reward points if it helps.

hymavathi_oruganti
Active Contributor
0 Kudos

USING JOINS FOR MORE THAN TWO TABLES IS NOT BETTER FOR PERFORMANCE.

1.U CAN ALSO CREATE VIEWS IN DICTIONARY AND USE THEM FOR BETTER PERFORMANCE

2. U CAN JOIN TWO TABLES AND PLCA IN AN ITAB

AND FOR ALL ENTRIES OF THAT ITAB U CAN SELECT FROM THE 3RD TABLE FOR BETTER PERFORMANCE.

3.U CAN ALSO USE 3 SEPARATE SELECTS.

Message was edited by: Hymavathi Oruganti

Former Member
0 Kudos

instead of join i think three selects wolud be betters.

first select from one table to a internal table .and use for all entries of that table to fetch the data from others

thanks,

Aditya

Former Member
0 Kudos

Hi Madan,

I feel join is the better way to fetch the data,

if you have common fields.

Thanks & Regards,

Siri.

Former Member
0 Kudos

HI Madan,

select from one table..

then use FOR ALL ENTRIES in itab

and then select from the join of the other two tables..

regards

satesh

Former Member
0 Kudos

HI madan

you can use both. But three select statement will be preferrable because all the three tables are of common fields.

regards

kishore

Former Member
0 Kudos

HI madan

Join is mainly used to fetch maching records from two or more tables.

if you have a common field there is no need for the join statement.

regards

kishore

Former Member
0 Kudos

If the number of records in these tables is small then use join:

But if the number of tables is more than 4. then avoid using JOINS.

If possible reduce the number of tables used in join by fetching data into internal tables.

Former Member
0 Kudos

hi

Selects would be better, still heck performance and decide.