Joining the tables

Hi all,
when i execute the below query i am getting error as
SQL> select a.(to_char(max(end_time),'DD-mon-YYYY HH24:MI:SS')),b.SEQUENCE# from v$rman_status a,V$ARCHIVED_LOG b where a.operation='BACKUP'
  2  and a.stamp=b.stamp;
select a.(to_char(max(end_time),'DD-mon-YYYY HH24:MI:SS')),b.SEQUENCE# from v$rman_status a,V$ARCHIVED_LOG b where a.operation='BACKUP'
ERROR at line 1:
ORA-01747: invalid user.table.column, table.column, or column specificationhow can i use this a.(to_char(max(end_time),'DD-mon-YYYY HH24:MI:SS')),???
thanks,
baskar.l

baskar.l wrote:
Hi all,
when i execute the below query i am getting error as
SQL> select a.(to_char(max(end_time),'DD-mon-YYYY HH24:MI:SS')),b.SEQUENCE# from v$rman_status a,V$ARCHIVED_LOG b where a.operation='BACKUP'
2  and a.stamp=b.stamp;
select a.(to_char(max(end_time),'DD-mon-YYYY HH24:MI:SS')),b.SEQUENCE# from v$rman_status a,V$ARCHIVED_LOG b where a.operation='BACKUP'
ERROR at line 1:
ORA-01747: invalid user.table.column, table.column, or column specificationhow can i use this a.(to_char(max(end_time),'DD-mon-YYYY HH24:MI:SS')),???
thanks,
baskar.lYou have to put the alias immediately before the column name.
select (to_char(max(a.end_time),'DD-mon-YYYY HH24:MI:SS')),b.SEQUENCE#
from v$rman_status a,V$ARCHIVED_LOG b
where a.operation='BACKUP'
and a.stamp=b.stamp
group by b.SEQUENCE#;

Similar Messages

  • Join the Table with View

    Hi,
    My doubt is can I join the table with view in the below where clause condition in the query. If yes, the below query will take 4 hrs to execute it. Can I do the below query to write as simplest?
    SELECT *
      FROM uabpymt p, uavlsum l
    WHERE uabpymt_appl_ind = 'N'
       AND uabpymt_amount > 5
       AND l.uavlsum_balance < 0
       AND l.uavlsum_cust_code = p.uabpymt_cust_code
       AND l.uavlsum_prem_code = p.uabpymt_prem_codeuavlsum ---view
    uabpymt ---table
    The view script below:
    CREATE OR REPLACE VIEW UAVLSUM
    (UAVLSUM_CUST_CODE, UAVLSUM_PREM_CODE, UAVLSUM_AMOUNT, UAVLSUM_BALANCE)
    AS
    SELECT cust_code,
           prem_code,
           SUM(amount),
           SUM(balance)
    FROM (
    SELECT uabopen_cust_code cust_code,
           uabopen_prem_code prem_code,
           uabopen_billed_chg amount,
           uabopen_balance balance
    FROM   uimsmgr.uabopen
    UNION ALL
    SELECT uabpymt_cust_code,
           uabpymt_prem_code,
           uabpymt_amount * -1,
           uabpymt_balance * -1
    FROM   uimsmgr.uabpymt
    UNION ALL
    SELECT uabadje_cust_code,
           uabadje_prem_code,
           uabadje_balance,
           to_number(0)
    FROM   uimsmgr.uabadje
    WHERE  uabadje_balance <> 0)
    GROUP BY cust_code,
             prem_code

    Find the below explain plan output which we get from the execute the query
    STATEMENT_ID            TIMESTAMP     REMARKS        OPERATION     OPTIONS          OBJECT_NODE OBJECT_OWNER            OBJECT_NAME            OBJECT_INSTANCE      OBJECT_TYPE OPTIMIZER      
                16/01/2009 05:57:24                   SELECT STATEMENT                                                                                                                           RULE                                                                                                                                                   
                16/01/2009 05:57:24                   FILTER                                                                                                                                                                                                                                    
                16/01/2009 05:57:24                   SORT           GROUP BY                                                                                                                                                                                                                      
                16/01/2009 05:57:24                   TABLE ACCESS           BY INDEX ROWID                     UIMSMGR                     UABPYMT                                1                                             
                16/01/2009 05:57:24                   NESTED LOOPS                                                                                                                                                                                                                                  
                16/01/2009 05:57:24                   VIEW                                                   UIMSMGR                                                         3                                             
                16/01/2009 05:57:24                   UNION-ALL                                                                                                                                                                                                                              
                16/01/2009 05:57:24                   TABLE ACCESS           FULL                            UIMSMGR                     UABOPEN                                    4                                             
                16/01/2009 05:57:24                   TABLE ACCESS           FULL                            UIMSMGR                     UABPYMT                                    5                                             
                16/01/2009 05:57:24                   TABLE ACCESS           FULL                            UIMSMGR                     UABADJE                                    6                                                                                                                                                         
                16/01/2009 05:57:24                   INDEX       RANGE SCAN                                   UIMSMGR                     UABPYMT_CUST_PREM_INDEX                        NON-UNIQUE                                                                                                                           
    Index column:
    Table name :UABPYMT
    Column Name
    UABPYMT_APPL_IND  
    UABPYMT_APPROVED_IND    
    UABPYMT_PYMT_DATE          
    UABPYMT_SOURCE    
    UABPYMT_ORIGIN                   
    UABPYMT_CUST_CODE          
    UABPYMT_PREM_CODE         
    UABPYMT_PYMT_DATE          
    UABPYMT_AR_TRANS             
    UABPYMT_GL_IND                  
    UABPYMT_GL_POST_DATE     
    UABPYMT_AR_TRANS  

  • The order of joining the tables in a query ANSI92

    Hi all!
    I have three table in Univerce.
    I need that those tables joined in next order:
    tab1 inner join tab2 right join tab3
    When creating a report in WebI they are connected as (regardless of the order of dimentions):
    tab1 right join tab3 inner join tab2
    How to set the correct order of joining the tables?
    OR
    how to change RIGHT OUTER JOIN on LEFT OUTER JOIN ?
    P.S. I use BO XI3.1, which not have parameter OUTERJOINS_GENERATION
    Thanks!

    it depends on your source system
    for example if you are using oracle, you can edit the link between the table and add this
    (+)
    for example
    TAB1.ID = TAB2.ID (+)
    AND TAB1.DEPT  = TAB2.DEPT(+)
    See the following link for discussing outer and inner joins for oracle
    http://www.dba-oracle.com/t_outer_joins.htm
    good luck
    Amr

  • How can i join the tables

    hai guys,
    can any body explain the table joining procedure step by step process.what is the necessay to join the tables
    Regards
    kiran

    Hi,
    Steps
    1. Enter t.code : SQVI
    2. Enter the name : TEST press the create button.
    3.Enter the title & Comments
    4.Select table to join
    5.Select the second icon (INSERT TABLE)
    6 enter table name : EKKO
    7.again insert table
    8.enter table name : EKPO
    Note the table you are joining should have COMMON field
    9. press green arrow button
    10. Select the  output parameters in table 1 -EKKO
    11  Select the output parameters in table 2 -EKPO
    12. select the  layout
    13 SAVE
    G.Ganesh Kumar

  • Help reqd to join the table of ADRC and MT001W tables

    Hi all,
    im working on PO and i need to display the delivery addresses where the records are available in these two tables.
    I want to join the table...so pls tell me which primary field key will work out for this...i've taken the record of name field from MT001W table but while i joining with ADRC table thru name2 = g_name2...its not getting printed.
    ****i've moved the MT001W-name2 to the variable g_name2.
    ****but when im matching the record with ADRC...its not coming..pls go thru the code once b4 reply.
    select name2 from MT001w into g_name2 where WERKS = g_xekpo-werks.
    endselect.
    if sy-subrc = 0.
    *move g_name2 to g_add.
    *endif.
    select house_num1 street post_code1 from adrc into (g_house , g_street , g_pcode)
    where name2 = g_name2 and langu = 'E'.
    endselect.
    *if
    *move g_street to i_street.
    endif.
    pls do the needful and reply ur comments on urgent basis.
    thanks & regards
    sankar.

    hi Madhavi t ,
    thanks a lot man....
    i've done it....
    thansk & regards
    sankar.

  • Unable to join the tables CDHDR, CDPOS

    Hello,
    I want to create a Query connecting tables CDHDR & CDPOS to extract cost center details which are changed. To be precise, when cost center details are changed using transactions KS02 & KS03, I want to extract those details and run the report. I am unable to join the tables using SAP Queries SQ01, SQ02, SQ03.
    Kindly suggest me regarding the same.
    Thanks in advance.
    Regards
    Sravan Mulumudi.

    Hi Jeve,
    I was testing the report S_ALR_87012308, but this displays changes done to G/L accounts. I have tried every possibility. Could you please explain further ?
    Regards
    Sravan.

  • I want to join the table vbrk,vbrp,konv and fields are vbeln, knumv.

    i want to join the table vbrk,vbrp,konv and fields are vbeln, knumv is possible .
    if it isn't possible. what is the another method output is doc. no.(vbrp-vbeln) condition doc. no.(vbrk-knumv) , condition(konv-kschl), tax rate(konv-mwsk1), quantitty(vbrp-fkimg) .reply pls... as soon as possible..

    Hi..
    This is the Join :
    SELECT VBAKVBELN VBRKKNUMV
                 VBRP~FKIMG
                 KONV-KSCHL  KONV~MWSK`
           FROM VBRK
           INNER JOIN VBRP
           ON VBRKVBELN = VBRPVBELN
           INNER JOIN KONV
           ON KONVKNUMV = VBRKKNUMV
           INTO TABLE <ITAB>
    WHERE <CONDITION>.
    REWARD IF HELPFUL.

  • I want to join the table vbrk,vbrp,konv but konv is cluster table .

    Hi
       konv is the cluster table . so   I  want to join the table vbrk,vbrp,konv and fields are vbeln, knumv is possible .
    if it isn't possible. what is the another method output is doc. no.(vbrp-vbeln) condition doc. no.(vbrk-knumv) , condition(konv-kschl), tax rate(konv-mwsk1), quantitty(vbrp-fkimg) .reply pls... as soon as possible..

    hi
    good
    1) Open
        Select
               Mard~matnr
               Makt~maktx
          From Makt
          Inner Join Mard
          on    Maktmatnr = Mardmatnr
          Where Makt~Spras = SY-LANGU
    2) Native Oracle
          SELECT Mard.matnr,
                 Makt.maktx
          From Makt, Mard
          Where Makt.mandt = Mard.mandt
            And Makt.matnr = Mard.matnr
            And Makt.mandt = :SY-MANDT
            And Makt.spras = :SY-LANGU
    3) KONV is Cluster - BAD LUCK!
        Select VBRK~VBELN
               VBRP~POSNR
               KONV~KSCHL
               KONV~KWERT    
          From ( VBRK Inner Join VBRP
                 On VBRKVBELN = VBRPVBELN )
               Inner Join KONV
                 On  VBRKKNUMV = KONVKNUMV
                 And VBRPPOSNR = KONVKPOSN
    4) KONV is Cluster - BAD LUCK!
        Select KONV~KNUMV
               KONV~KPOSN
               KONV~KSCHL
               KONV~KWERT    
          From KONV
          Where KONV~KNUMV in (
               Select VBRK~KNUMV
                 From VBRK Inner Join VBRP
                 On VBRKVBELN = VBRPVBELN
                Where VBRKKNUMV = KONVKNUMV
                  And VBRPPOSNR = KONVKPOSN
    5) Open
             Select VBRP~MATNR
                    Sum( VBRP~NETWR )
              From VBRP
              Group By VBRP~MATNR 
    6) Native Oracle        
             Select VBRP.MATNR ,
                    Sum( VBRP.NETWR )
              From VBRP
              Where mandt = :sy-mandt
              Group By VBRP.MATNR         
    7) Native Oracle
             Select VBRP.MATNR ,
                    Count( VBRP.NETWR ),
                    Sum( VBRP.NETWR )
              From VBRP
              Where mandt = :sy-mandt
              Group By VBRP.MATNR    
    8) Open
             Select VBRP~MATNR
                    makt~maktx
                    Sum( VBRP~NETWR )
              From VBRP inner Join MAKT
                On VBRPMATNR = MAKTMATNR
              Where MAKT~SPRAS = SY-LANGU
              Group By VBRPMATNR maktmaktx      
    9) Native Oracle         
             Select VBRP.MANDT,
                    VBRP.MATNR,
                    MAKT.MAKTX,
                    Sum( VBRP.NETWR )
              From VBRP , MAKT
             Where  VBRP.MANDT = MAKT.MANDT
               And  VBRP.MATNR = MAKT.MATNR
               And  MAKT.SPRAS = :SY-LANGU
              Group By VBRP.MANDT, VBRP.MATNR, MAKT.MAKTX   
    10) Open          
         SELECT EKET~EBELN 
                EKET~EINDT 
                EKET~WAMNG 
                EKET~WEMNG 
          From  ( ekko INNER JOIN ekpo
                  ON  ekkomandt = ekpomandt
                  AND ekkoebeln = ekpoebeln
                INNER JOIN eket
                ON  ekpomandt = eketmandt
                AND ekpoebeln = eketebeln
                AND ekpoebelp = eketebelp
                AND EKET~WAMNG > 0
                AND EKETWAMNG <> EKETWEMNG
         Where EKPO~MATNR = 'NB220'
           And EKPO~WERKS  In ('P001', 'P004', 'L004')
           And EKKO~BSTYP = 'F'
           And EKKO~BSART = 'UB'
           And EKPO~ELIKZ <> 'X'
           And EKKO~LOEKZ <> 'X'     
    11) Native Oracle      
         SELECT EKET.EBELN, 
                EKET.EINDT, 
                EKET.WAMNG, 
                EKET.WEMNG 
          FROM  ( ekko INNER JOIN ekpo
                  ON  ekko.mandt = ekpo.mandt
                  AND ekko.ebeln = ekpo.ebeln
                INNER JOIN eket
                ON  ekpo.mandt = eket.mandt
                AND ekpo.ebeln = eket.ebeln
                AND ekpo.ebelp = eket.ebelp
                AND EKET.WAMNG > 0
                AND EKET.WAMNG <> EKET.WEMNG
         Where EKPO.MATNR = 'NB220'
           And EKPO.WERKS  In ('P001', 'P004', 'L004')
           And EKKO.BSTYP = 'F'
           And EKKO.BSART = 'UB'
           And EKPO.ELIKZ <> 'X'
           And EKKO.LOEKZ <> 'X'
    thanks
    mrutyun^

  • Doubt in attribute view on joining the table .

    Hello Team
                        Can some please help me in clearing the following doubts on joining tables .
    i) Can we perform a self join in attribute view in HANA . like for ex :- joining a table to itself .
    ii)Can we create an analytic view without creating an attribute view i.e creating an analytic view directly on tables .
    iii)When aggregation happens in calculation view exactly what happens internally .
    Please suggest me with the solution of these doubts .
    Regards

    Hi Prag,
    As Rashmi has answered your question, i would like to add up to it few more important points.
    1. Do not perform self join as it will return uncertain results. It is better to avoid self join.
    You can create a copy of the same table and perform join which will be consistent.
    2. In an analytic view, you will be adding table to data foundation, select the output fields.In the logical join node by default your data foundation will be present (this will contain the fields that you selected for output), you need not add any attribute view to this logical join node, leave it to default. In the semantics node select the attributes and measures. Perform validation and then activate. Your analytic view without attribute view is ready. You can check the data preview.
    3. In a calculation view, the records gets grouped by all the attributes and then the measures are calculated based on this grouping by using the mentioned aggregation (sum/max/min).
    Eg.
    Customer ID 0Calmonth Amount (aggregation = max)
    1001               01.2014     100         
    1001               01.2014     400
    1002               01.2014     200
    Output:
    Customer ID 0Calmonth Amount (aggregation = max)
    1001               01.2014     400
    1002               01.2014     200
    Hope this clarifies your doubts.
    Thanks and Regards,
    M.N.Adinarayanan

  • Joining the Tables VBAK and CDHDR

    Hi All,
    I am a novice to SAP, and probably have the most basic question. I need to join the two tables VBAK and CDHDR and I dont see any common fields between them.
    I would need to do this for as generating a custom report that lists all the valid contracts created or changed within the period of selection. I also need to show the old value and the new value, the user ID of who made the change/creation and the date of the change.
    Anyhelp in this regard is highly appreciated and will be rewarded appropriately.
    Many thanks in anticipation.

    CDHDR is used for each and every table of SAP, so don't look for common key with your table.
    Look for records in CDHDR with OBJECTCLAS = 'VERKBELEG' and OBJECTID = VBAK-VBELN, and then in CDPOS with keys of CDHDR and tabname = 'VBAK'  and tabkey = VBAK-VBELN. (You also get VBAP and other tables under the same Id)
    Take a look at report RVSCD100
    Regards

  • Joining the tables in report painter/writer

    Friends,
    Can we join tables in report painter / writer?
    Regards
    HK

    Hello
    table joining required if you want a report wherein you need field from more than one table with interlinked field. Then create infoset in SQ02 and use that infoset and create Query in SQ01 and design as per requirement. Abap coding also possible here
    Report writer/pointer you can refer table for any feld requirement, no need to join thats only viewing
    hope I answer u properly
    Regards
    Dinabandhu

  • In query SQVI unable to join the table konv

    Hi Guru's
    I have a requirement from the user, extract the Open PO's with INCO TERMS and CONDITION TYPES.
    1. what is the process to extract the OPEN PO's from table EKKO.
    In normal process I can extract Open PO's from ME2L and for a perticular Open PO number i can get the INCO TERMS and DOC CONDITION number from table EKKO and by taking the DOC CONDITION number I can get the condition type from table KONV.
    But I want to do this process in SQ01 how is it possible?
    please help
    Regards
    ISM

    ISM,
    No.  Such instructions are beyond the scope of these forums, or at least beyond the scope that I would be willing to cover.  FYI SAP provides a class  [BC407 Reporting|http://www.sap.com/usa/services/education/tabbedcourse.epx?context=%5b%5b%7cBC407%7c%7c%7c063%7cUS%7c%5d%5d%7c] to cover such topics.  The class lasts for 2 days. 
    I can say that I have created a query that meets requirements that are similar to yours.  It took me a couple of hours to rough out the original version for user testing, and a couple more hours to finalize for production.  It is do-able.
    Following is a link to the Query Help doc.  This was the doc from which I learned SAP Query (I did have previous experience with other report writers)   http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVQUE/BCSRVQUE.pdf  
    I have already given you the general methodology to obtain your data within SAP Query.  If these guidelines are not adequate, then you would probably be better off engaging the services of a programmer to write a custom report.
    Best Regards,
    DB49

  • Given the table and data below, without joining the table to itself, how do

    Hi
    could you please help me about following?
    create table units
    ( report_date date
    , company_id number
    , units number );
    insert into units values ('1-jan-2010', 1, 28);
    insert into units values ('3-jan-2010', 2, 20);
    insert into units values ('7-jan-2010', 2, 10);
    insert into units values ('1-jan-2010', 2, 10);
    insert into units values ('2-jan-2010', 1, 30);
    insert into units values ('3-jan-2010', 1, 49);
    insert into units values ('4-jan-2010', 2, 40);
    I want the report to look like this:
    Company_id | report_date | daily_units | month_to_date_units
    1 | 1/1/2010 | 28 | 28
    1 | 1/2/2010 | 30 | 58
    1 | 1/3/2010 | 49 | 107
    2 | 1/1/2010 | 10 | 10
    2 | 1/3/2010 | 20 | 30
    2 | 1/4/2010 | 40 | 70
    2 | 1/7/2010 | 10 | 80
    Regards

    Hi,
    Try this:
    SQL> ed
    Wrote file afiedt.buf
      1  select report_date,company_id,units ,
      2* SUM(units) OVER ( PARTITION BY company_id,TO_CHAR(report_date,'MON-YY') ORD
    ER BY company_id,report_date) FROM units
    SQL> /
    REPORT_DA COMPANY_ID      UNITS
    SUM(UNITS)OVER(PARTITIONBYCOMPANY_ID,TO_CHAR(REPORT_DATE,'MON-YY')ORDERBYCOMPANY
    01-JAN-10          1         28
                                                                                  28
    02-JAN-10          1         30
                                                                                  58
    03-JAN-10          1         49
                                                                                 107
    01-JAN-10          2         10
                                                                                  10
    03-JAN-10          2         20
                                                                                  30
    04-JAN-10          2         40
                                                                                  70
    07-JAN-10          2         10
                                                                                  80
    7 rows selected.

  • Can we join the transparent and pooled tables?

    hi friends,
    i have a doubt that is when we want to get the data from transparent and pooled tables it is not possible to join the tables.
    so should we go with nested select statements or is there any way to get the data? with better performance
    if i go with nested select statements it takes a lot time thats y i need a better way
    for example i want the data from BKPF and BSEG based on BELNR
    please send me how can we get it
    regards
    jagadish

    hi rob
    thanks for response
    see the below code once
    SELECT * FROM bkpf
              WHERE gjahr = p_gjahr
              AND ( monat BETWEEN lv_1st_mth AND gw_prev_monat ).
    *- Selection with cost center
          IF  gw_kostl NE SPACE.
                 s_kostl = s_kostl+3(10).
                 SELECT * FROM bseg
                      WHERE bukrs = bkpf-bukrs
                      AND   belnr = bkpf-belnr
                      AND   gjahr = bkpf-gjahr
                      AND   kokrs = p_kokrs
                      AND   kostl IN s_kostl
                      AND   buzei = '001'
                      AND   lstar <> ' '.
                 MOVE bseg-lstar TO itab2-lstar .
                 MOVE bkpf-bukrs TO itab2-bukrs.
                 MOVE bkpf-belnr TO itab2-belnr.
                 MOVE bkpf-gjahr TO itab2-gjahr.
                 MOVE bkpf-monat TO itab2-monat.
                 MOVE bkpf-budat TO itab2-budat.
                 MOVE bseg-kokrs TO itab2-kokrs.
                 MOVE bseg-buzei TO itab2-buzei.
                MOVE bseg-wrbtr TO itab2-wrbtr.
    *Changed----
                 IF bseg-shkzg = 'H'.
                   lv_wrbtrcd = 0 - bseg-wrbtr.
                   itab2-wrbtr = lv_wrbtrcd.
                 ELSEIF bseg-shkzg = 'S'.
                   MOVE bseg-wrbtr TO itab2-wrbtr.
                 ENDIF.
                 MOVE bseg-fdwbt TO itab2-fdwbt.
                 MOVE bseg-sgtxt TO itab2-sgtxt.
                 MOVE bseg-kostl TO itab2-kostl.
                 APPEND itab2.
                 ENDSELECT.
          ELSE.
                 s_kostl = p_estat+0(4).
                 SELECT * FROM bseg
                      WHERE bukrs = bkpf-bukrs
                      AND   belnr = bkpf-belnr
                      AND   gjahr = bkpf-gjahr
                      AND   kokrs = p_kokrs
                      AND   kostl IN s_kostl
                      AND   buzei = '001'
                      AND   lstar <> ' '.
                 IF bseg-kostl+0(4) = s_kostl.
                     MOVE bseg-lstar TO itab2-lstar.
                     MOVE bkpf-bukrs TO itab2-bukrs.
                     MOVE bkpf-belnr TO itab2-belnr.
                     MOVE bkpf-gjahr TO itab2-gjahr.
                     MOVE bkpf-monat TO itab2-monat.
                     MOVE bkpf-budat TO itab2-budat.
                     MOVE bseg-kokrs TO itab2-kokrs.
                     MOVE bseg-buzei TO itab2-buzei.
                    MOVE bseg-wrbtr TO itab2-wrbtr.
    *Changed----
                 IF bseg-shkzg = 'H'.
                   lv_wrbtrcd = 0 - bseg-wrbtr.
                   itab2-wrbtr = lv_wrbtrcd.
                 ELSEIF bseg-shkzg = 'S'.
                   MOVE bseg-wrbtr TO itab2-wrbtr.
                 ENDIF.
                     MOVE bseg-fdwbt TO itab2-fdwbt.
                     MOVE bseg-sgtxt TO itab2-sgtxt.
                     MOVE bseg-kostl TO itab2-kostl.
                     APPEND itab2.
                 ENDIF.
                 ENDSELECT.
          ENDIF.
          ENDSELECT.
    regards
    jagadish

  • Issues while joining two tables as the joining column has duplicate values - Please help!

    Hi,
    I have a table A -which has few columns including a Amount column - I am joining this table A to Table B. The joining column in B has duplicates.  So, the number of records are getting more after the joining. As per the requirment when I create a table
    after joining the tables and count the salary clumn, there is a difference in the counting. How can I solve this? Can you please help me?
    Here is the DDL and sample values
    create table #student (sid int, name varchar(10),salary int)
    create table [#address] (sid int, city varchar(10),grade char(1),lineneumber int)
    insert into #student values (1,'sachin',8000)
    insert into #student values (2,'Dhoni',2000)
    insert into #student values (3,'Ganguly',7000)
    insert into #student values (4,'Kohli',1000)
    insert into [#address] values(1,'mumbai','A',1)
    insert into [#address] values(1,'mumbai','B',2)
    insert into [#address] values(1,'mumbai','C',3)
    insert into [#address] values(1,'mumbai','D',4)
    insert into [#address] values(2,'JARKHAND','D',3)
    insert into [#address] values(2,'JARKHAND','D',4)
    SELECT S.SID,NAME,salary,CITY ,grade,linenumber
    into #FINAL
    FROM #STUDENT S
    LEFT JOIN #ADDRESS A
    ON S.SID=A.SID
    SELECT SUM(salary) FROM #FINAL
    --44000
    Final result should be 18000 , but it is coming as 44000. can you please help me to get the correct result - what do i do in the joining?
    In my real project, i have 5 tables joining, each table have more than 30 columns and few joining tables joining column have duplicates. I have simplified the issue so that i can ask the question clearly. So,while answering, please consider that also in mind.
    thanks in advance for your help!

    SELECT S.SID,NAME,salary,CITY 
    into #FINAL
    FROM #STUDENT S
    LEFT JOIN (SELECT DISTINCT sid,city
    FROM #Address) A
    ON S.SID=A.SIDthis will do a join on student table and city table with unique sid and city name so adddress selection will be sid city1 mumbai2 jarkand

Maybe you are looking for