Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is it Possible to join 4 or more tables in a Select Statement?

Former Member
0 Kudos

Hello guys,

Can I do Inner Join 4 or 5 tables in a select statement?

1 ACCEPTED SOLUTION

abdul_hakim
Active Contributor
0 Kudos

Hi Maui,

Basically there are no limits,You can have as many number of tables as you wish.

Regards,

Abdul Hakim

12 REPLIES 12

Former Member
0 Kudos

Maui,

Yes it is possible, however, it might have an impact on the performance.

regards,

Ravi

Note : Please mark the helpful answers.

0 Kudos

YA U CAN JOIN AS MANY TABELS U REQUIRED BUT U FACE

performance PROBLEM

0 Kudos

How come? How will I do it?

like:

FROM (table1 as x JOIN table2 as y

ON xf1 = yf1)

INNER JOIN table3 as a

ON af1 = xf1...

how about the 4th table?

0 Kudos

Hi,

See my previous post.

It has an example.

0 Kudos

Hi maui,

you can keep joining tables as wenceslaus did..

but is highly recommended no to use JOINS more than three times....

IN case you just want to make it ..

use FOR ALL ENTRIES..

regards

satesh

Message was edited by: Satesh R

0 Kudos

U HAVE TO SERCH FOR KEY FIELD FOR THAT . MEANS HOW TABELS ARE RELATED EACH OTHE FOR THIS U ALSO USE SQ02

FOR EXAMPLE

SELECT bkpf~belnr

bkpf~gjahr

bkpf~bukrs

bkpf~blart

bkpf~bldat

bkpf~budat

bkpf~usnam

bkpf~tcode

bkpf~xblnr

bsik~lifnr

bsik~bupla

bsik~secco

INTO CORRESPONDING FIELDS OF TABLE itab_pur

FROM bkpf INNER JOIN bsik

ON bkpfbelnr = bsikbelnr

and bkpfbukrs = bsikbukrs

WHERE bkpf~bukrs IN co_code

AND bkpf~budat IN pos_dt

AND bkpf~tcode IN t_code

AND bsik~secco IN se_code.

U CAN ALSO ADD MORE TABLE BASED ON CONDITION

0 Kudos

Thanks Guys! But how will the peformance affect this type of statement?

0 Kudos

Hi Maui,

õ Keep the result set small!

1. E.g. use WHERE conditions

õ Minimize the amount of data transferred!

2. E.g. use field lists and aggregate functions

õ Minimize the number of transfers!

3. E.g. use joins (not more than 3)and subqueries

õ Minimize the search overhead!

4. The data base should use an appropriate index

õ Reduce the database load!

5. All users share one data base

regards

satesh

abdul_hakim
Active Contributor
0 Kudos

Hi Maui,

Basically there are no limits,You can have as many number of tables as you wish.

Regards,

Abdul Hakim

0 Kudos

Yes you can do. But avoid more than 5 tables in the join.

SELECT vbak~vbeln vbak~vkorg vbak~vtweg vbak~spart vbap~posnr
vbap~matnr vbap~zmeng likp~lfart likp~lfdat lips~lfimg
FROM ( ( ( vbak INNER JOIN vbap ON vbak~vbeln = vbap~vbeln ) INNER JOIN
lips ON vbak~vbeln = lips~vgbel ) INNER JOIN likp ON likp~vbeln =
lips~vbeln ) INTO TABLE i_data where vbap~posnr = lips~vgpos
AND vbak~vbeln IN s_vbeln

Former Member
0 Kudos

Yes, we can do, but it may give some performance issues so btter to use For All Entries.

Ram

Former Member
0 Kudos

Hi

Yes,you can access data from 4 or 5 tables using Inner Join.

If you want the syntax you can ask for that.

Thanks

Mrutyunjaya Tripathy