Skip to Content
author's profile photo Former Member
Former Member

fetch three tables

Is it possible to fetch 3 tables with single select query(without using view)

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 07:50 AM

    We can use JOIN to select from 2 or more tables.

    But JOIN wont work for pooled/cluster tables

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 09:15 AM

    hi

    good

    use the join statement to join any number of table using a single select statement.

    thanks

    mrutyun^

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 09:24 AM

    Hi,

    Yes, you can use JOIN or FOR ALL ENTRIES. Performance wise, For All Entries is better.

    Try like this:

    <u><b>JOIN:</b></u>

    select zfpcdcadivi zfpcdproforma zfpcdfactura zfpcdaniofactura

    zfpcdmontousd zfpcdmontoap zfpcdebeln zfpcdinco1

    zfpcdlifnr lfa1name1 zcdvsstatus zfpcdconint

    into it_lista

    from zfpcd inner join zcdvs

    on zfpcdebeln = zcdvsebeln

    and zfpcdproforma = zcdvsproforma

    and zfpcdlifnr = zcdvslifnr

    inner join lfa1

    on zfpcdlifnr = lfa1lifnr

    where zcdvs~status = '04'.

    <u><b>FOR ALL ENTRIES:</b></u>

    SELECT likpvbeln likplifex likpbldat likpwadat likpwadat_ist likpkodat likp~lfart

    likpkunnr likpvstel lipsposnv lipslfimg lipsvrkme lipslgmng lips~meins

    lipswerks lipslgort lipscharg lipsvbelv lipsposnr lipsmatnr

    lipsvbeln LIPSVGBEL LIPSVGPOS vbupkosta vbupwbsta vbupposnr vbup~vbeln

    • VBAKIHREZ VBAKVBELN VBAP~VBELN

    INTO CORRESPONDING FIELDS OF TABLE it_itab

    FROM ( likp

    INNER JOIN lips

    ON lipsvbeln = likpvbeln

    INNER JOIN vbup

    ON vbupposnr = lipsposnr

    and VBUPVBELN = LIPSVBELN )

    • left outer join VBAK

    • on VBAKVBELN = LIPSVGBEL

    • inner join VBAP

    • on VBAPVBELN = VBAKVBELN )

    WHERE likp~vbeln IN so_vbeln

    AND likp~lifex IN so_lifex

    AND likp~lfart IN so_lfart

    AND likp~kunnr IN so_kunnr

    AND likp~vstel IN so_vstel

    AND likp~bldat IN so_bldat

    AND likp~wadat_ist IN so_wadat

    AND vbup~kosta IN so_kosta

    AND vbup~wbsta IN so_wbsta

    AND LIPS~LFIMG NE 0.

    Regards,

    Bhaskar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 09:59 AM

    Inner joins are obsolete so i don't want to use them without using "view" and "joins" is it possible to fetch records from 3 tables using single select query.

    I don't think i got a proper answer to the above ques.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 07:46 AM

    Hi,

    Yes it is possible through JOIN.

    check the below code

    PARAMETERS: p_cityfr TYPE spfli-cityfrom,

    p_cityto TYPE spfli-cityto.

    DATA: BEGIN OF wa,

    fldate TYPE sflight-fldate,

    carrname TYPE scarr-carrname,

    connid TYPE spfli-connid,

    END OF wa.

    DATA itab LIKE SORTED TABLE OF wa

    WITH UNIQUE KEY fldate carrname connid.

    SELECT ccarrname pconnid f~fldate

    INTO CORRESPONDING FIELDS OF TABLE itab

    FROM ( ( scarr AS c

    INNER JOIN spfli AS p ON pcarrid = ccarrid

    AND p~cityfrom = p_cityfr

    AND p~cityto = p_cityto )

    INNER JOIN sflight AS f ON fcarrid = pcarrid

    AND fconnid = pconnid ).

    LOOP AT itab INTO wa.

    WRITE: / wa-fldate, wa-carrname, wa-connid.

    ENDLOOP.

    Message was edited by:

    Velangini Showry Maria Kumar Bandanadham

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 09:29 AM

    HI,

    YOU CAN USE THE INNER JOIN QUERY AS SYNTAX FOLLOWS

    <b>SELECT A<field1> A<field2> B<field1> B<field2> C<field1> C<field2>

    INTO TABLE ITAB

    FROM (MARA AS A INNER JOIN MAKT AS B

    ON AFIELD1 = BFIELD1) INNER JOIN MARC AS C ON ON AFIELD1 = CFIELD1</b>.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 13, 2007 at 09:33 AM

    YES IT CAN BE POSSIBLE BY JOINES AND FOR ALL ENTRIES

    IF U WANT GOOD PERFORMANCE GO FOR FOR ALL ENTRIES

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.