Combining tables

Hi guys,
I'm having two separate tables
table A with column 'CUST_ID' and column 'COUNT'
table B with column 'CUST_ID' and column 'COUNT'
I'm facing problem in combining both table by adding the col 'COUNT' from two different table if the 'CUST_ID' is the same.
e.g.
I would like to add up the COUNT and combine the CUST_ID into one:
TABLE A
CUST _ID     COUNT
AB_123 58
TABLE B
CUST _ID     COUNT
AB_123 2
RESULT:
CUST _ID     COUNT
AB_123 60
Pls advice
thanks.
Ivan Baros

select cust_id, count(1)
from
       ( select cust_id
         from table_a
         union all
         select cust_id
         from table_b
group by cust_idExample:
SQL> select deptno, count(1)
  2  from scott.emp
  3  group by deptno;
    DEPTNO   COUNT(1)
        30          6
        20          5
        10          3
SQL> select deptno, count(1)
  2  from
  3     (select deptno
  4      from scott.emp tab_a
  5      union all
  6      select deptno
  7      from scott.emp tab_b
  8     )
  9  group by deptno;
    DEPTNO   COUNT(1)
        30         12
        20         10
        10          6
SQL> Cheers,

Similar Messages

  • Re:User group,info set and Query combination table

    Hi,
      I would like to know the combination table of User group,info set and Query.
    Can any body please respond to my question?
    Regards,
    Suresh Kumar.

    Hi,
    Check the tables starting with AQG*.
    Reward points if useful.
    Regards,
    Atish

  • Condition records and tax code combination table

    CAn I know the table where both condition record and tax code stored.

    Hi Jose,
    I think you have quoted the tax procedure table.  There i have not found the tax codes. 
    My requirement is both condition records and tax codes combination table.
    I want to see for which condition type which tax code has been assigned.

  • Error in flex item, combinations table for this flexfield has more 1 entry

    HI OAF Gurus,
    I setup a flex item with the following attributes:
    ID = CostAllocationKFF
    Item Style = flex
    View Instance = XXPerAsgDetailsVO
    Rendered = true
    Appl Short Name = PAY
    Name = COST
    Type = key
    Segment List = XXPAY_COST_ALLOCATION|Company|Cost Centre
    In my controller, I have the following code in processRequest to bind the KFF against the CostAllocationKFF item:
    String costFlexStrucCode = "XXPAY_COST_ALLOCATION";
    boolean flag1 = false;
    OAKeyFlexBean oacostallockeyflexbean = (OAKeyFlexBean)webBean.findIndexedChildRecursive("CostAllocationKFF");
    if(oacostallockeyflexbean != null)
    oacostallockeyflexbean.useCodeCombinationLOV(flag1);
    oacostallockeyflexbean.setCCIDAttributeName("CostAllocKeyflexId");
    oacostallockeyflexbean.setStructureCode(costFlexStrucCode);
    Now, at processRequest it is picking up the right segment values. However, when I dont update the segments and I hit a button that will eventualy call processFormRequest, it is giving me the following error,
    "The combinations table for this flexfield contains more than one entry that matches the entered values. Inform your system administrator that the combination identified by the number 6419 is duplicated."
    Is there anything that I'm missing? What should I do to refrain from such error happening? I also have a flex item for people group but it is not giving me the same error message. Please advise. Thank you very much.

    can someone help shed light on this? I'm still trying to find out what's causing this issue. Thanks!

  • Combine tables with common data - union

    Hi,
    sorry if this has already been posted but I couldn't find a similar thread out there.
    I have two small tables where there are duplicate parts. I'd like to combine the two into 1.
    Table 1
    Part_Num
    Serialized_Part
    Table 2
    Part_Num
    Hazardous_Part
    a part can be both serialized and hazardous. I'd like to simply create a table
    Final Table
    Part_Num - distinct value combining tables.
    Serialized_Part - value from table 1
    Hazardous_Part - value from table 2
    My SQL needs some work.
    Thanks in advance,
    --TD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hi,
    Welcome to the forum!
    Whenever you have a question, it helps if you post a little sample data in a form people can use, for example:
    CREATE TABLE     Table_1
    (     Part_Num     NUMBER (6)     PRIMARY KEY
    ,     Serialized_Part     VARCHAR2 (10)
    INSERT INTO table_1 (part_num, serialized_part) VALUES (1,  'Widget');
    INSERT INTO table_1 (part_num, serialized_part) VALUES (2,  'Fubar');
    CREATE TABLE     Table_2
    (     Part_Num     NUMBER (6)     PRIMARY KEY
    ,     Hazardous_Part     VARCHAR2 (12)
    INSERT INTO table_2 (part_num, hazardous_part) VALUES (2,  'Acid');
    INSERT INTO table_2 (part_num, hazardous_part) VALUES (3,  'Knife');
    CREATE TABLE     Final_Table
    (     Part_Num     NUMBER (6)     PRIMARY KEY
    ,     Serialized_Part     VARCHAR2 (10)
    ,     Hazardous_Part     VARCHAR2 (12)
    );Also post the results you want from that data. In this case, I think you want final_table, which starts with no rows, to contain this data when everything is finished:
    . PART_NUM SERIALIZED HAZARDOUS_PA
             1 Widget
             2 Fubar      Acid
             3            KnifeHere's one way to get those results:
    INSERT INTO     final_table (part_num, serialized_part, hazardous_part)
    WITH     combined_data     AS
         SELECT     part_num
         ,     serialized_part
         ,     NULL     AS hazardous_part
         FROM     table_1
         UNION
         SELECT     part_num
         ,     NULL     AS serialized_part
         ,     hazardous_part
         FROM     table_2
    SELECT       part_num
    ,       MIN (serialized_part)     AS serialized_part
    ,       MIN (hazardous_part)     AS hazardous_part
    FROM       combined_data
    GROUP BY  part_num
    ;You had the right idea with UNION, but UNION may leave two rows with the same part_num. GROUP BY can combine any number of rows into one. Since, at most, one those rows will have a serialized_part, and, likewise, at most one of those rows will have a hazardous_part, then it doesn't matter if you use MIN or MAX to get that one value.

  • Combining tables with multi-column keys using NOT EQUALS

    Hi, I am trying to perform a query in SQL to find a particular person who has a value for an attribute that nobody else has, so far my query looks like this:
    SELECT CS1.*
    FROM COMPANYSTAFF CS1
    WHERE NOT EXISTS
    (SELECT * FROM COMPANYSTAFF CS2 WHERE CS1.COMPSTAFFID != CS2.COMPSTAFFID AND CS1.MAININTEREST = CS2.MAININTEREST)
    GO
    The problem is that the table represents a weak entity, so the primary key is the name of the company the person works for combined with his ID. I want to change the not equals part of the above query so that I can say CS1-CompanyName and ID is not Equal to CS2-Company Name and ID rather than just both seperately.
    In order to clarify what probably sounds really stupid I would really like the ability to say something like:
    (CS1.COMPNAME, CS1.COMPSTAFFID) != (CS2.COMPNAME, CS2.COMPSTAFFID)
    Does anyone know if this is possible or if there is another way around it?
    Thanks
    Dave

    So ?
    SELECT CS1.*
    FROM COMPANYSTAFF CS1
    WHERE NOT EXISTS
    (SELECT * FROM COMPANYSTAFF CS2 WHERE (CS1.COMPSTAFFID != CS2.COMPSTAFFID OR CS1.COMPNAME != CS2.COMPNAME)
    AND CS1.MAININTEREST = CS2.MAININTEREST)GO ?
    Is is MS SQL ? :-)
    Regards
    Dmytro

  • Combine tables from 2 SQL servers with different Schemas and update as new data is entered

     I have 2 SQL server 2000 machines, I need to take a table from each one and combine them together based on a date time stamp.  The first machine has a database that records information based on an event it is given a timestamp the value of variable is stored and a few other fields are stored in Table A.  The second machine Table B has test data entered in a lab scenario.  This is a manufacturing facility so the Table A data is recorded by means of a third party software.  Whenever a sample is taken in the plant the event for Table A is triggered and recorded in the table.  The test data may be entered on that sample in Table B several hours later the lab technician records the time that the sample was taken in Table B but it is not exact to match with the timestamp in Table A.  I need to combine each of these tables into a new SQL server 2005 database on a new machine.  After combining the tables which I am assuming I can based on a query that looks at the timestamp on both Tables A & B and match the rows up based on the closest timestamp. I need to continuously update these tables with the new data as it comes in.  I havent worked with SQL for a couple of years and have looked at several ways to complete this task but havent had much luck.  I have researched linked servers, SSIS, etc Any help would be greatly appreciated.

    Hi Catalyst,
    Welcome to the MSDN Forums!
    I would have a concern with respect to your issue.  If there is no way to identify a sample, save for the closest timestamp on table A - what would happen if two samples were taken in the plant, and the test results were entered in reverse order?  The samples would not tie back to the appropriate measurements.  Can't you get an identifier of some sort to tie that sample back to table A?
    If you can't, something like this should work, but I'm not sure how you'll "serialize" the samples to avoid the situation above.
    Code Snippet
    --Create sample data
    DECLARE @TableA TABLE ( SampleNo int NOT NULL,
    SampleTime datetime);
    DECLARE @TableB TABLE ( SampleTakenTime datetime,
    SampleColour varchar(50),
    SampleQuality char(1),
    SampleResultNo int);
    INSERT @TableA SELECT 1, GETDATE()
    WAITFOR DELAY '00:00:10';
    INSERT @TableB SELECT GETDATE(), 'Orange', 'A', '5'
    WAITFOR DELAY '00:00:20';
    INSERT @TableB SELECT GETDATE(), 'Purple', 'D', '7'
    WAITFOR DELAY '00:00:10';
    INSERT @TableA SELECT 2, GETDATE()
    --Actual Query begins now
    SELECT *
    FROM @TableA AS a
    JOIN @TableB AS b ON ABS(DATEDIFF(millisecond,a.SampleTime,b.SampleTakenTime)) = (SELECT MIN(ABS(DATEDIFF(millisecond,ta.SampleTime,tb.SampleTakenTime)) )
    FROM @TableB tb
    JOIN @TableA ta ON a.SampleNo = ta.SampleNo)
    Now, to account for the fact that you are querying data from a different server, you need to create a linked server (see sp_addlinkedserver and sp_addlinkedsrvlogin) and then use the fully qualified name (server.database.schema.table) to reference the table.
    Hope this helps,
    Aaron

  • How to combine Tables GLPCA & GLPCP

    Hi All,
    I have a requirement to show Actual and Plan values for Material and GL Accounts in a Report.
    The Actual values come from GLPCA table and the Plan values come from GLPCP table. But the problem is that the GLPCP table continas the values on period basis.
    Could you please help me find a solution on how to combine data from these 2 tables and display in the report.

    Hi Sandeep
    We had the same scenario in our project too. Our approach was - We create two independant DSOs, one for holding data from GLPCA and another from GLPCP. Please note GLPCA will contain data at the lowest denomination meaning at the day level, whereas GLPCP will contain at the period level. In order to achieve reporting from both we created a multiprovider where fiscal period from both the DSO's was included in the multiprovider (do not include calendar day) so that when you report GLPCA data will be aggregated at the period level and GLPCP data already at the period level will both be shown in a single row with common characteristics like Profitcenter, material, Customer etc.
    I hope this helps.
    Thanks.

  • Combining table fields

    Hi,
    I'm mysql, PHP and DW
    I have a table named 'people' made of three columns, id , first_name and last_name.
    I need to run a sql sentence where i get the id field as it is and the other 2 fields combined together as fullname.
    i tried this as a recordset in DW5 but i got an error message:
    Select people.id, people.first_name&' '& people.last_name As fullname
    from poeple,
    thanks for help
    Joe

    SELECT id, CONCAT(first_name, ' ', last_name) As fullname FROM people
    The correct term is concatenate, not combine. That's probably why you didn't find anything by searching.
    http://www.google.com/search?q=concatenate+sql+table+fields

  • Combined Table/Report/ Transaction

    Hi All,
    Is there any Report/ Tables/Transaction available which contains all these below details in one,
    Material
    Plant
    Batch
    Blocked Stock
    Material Document and
    Reason for Movement
    Even In Tables- MCHB and MSEG, all the above are not available in one.
    Pl. advice.
    Regards,
    Kumar

    Hi,
    As I mentioned your desired report is a mix of stock report & material movements.
    How can you realize this?
    E.g.
    Your blocked stok of materilA is 100 pcs. Let's say this stock come into existence via 5 material movememts (via 343 & 344). How can you display (one stock value and 5 movements) in one line?
    Or you booked 50 pcs of materialA into blocked stock (343) than you booked 20 pcs of this (from blocked) to unrestricted (344). This means you have 30 pcs as blocked stock and you have two material documents. How can you report this?
    What is the sense of your report?
    Please give details about your goal you want to achieve.
    BR
    Csaba

  • Combine table 3 columns in a combo box?

    I need a combo box to display "lastName, firstName - phone".
    I have these 3 columns in my database. Can anyone provide a short
    cfc to xml script I could use to create an arrayCollection to use
    as a dataprovider for my combobox?
    I'm thinking along the lines of a CFQUERY in a cfc, then
    exporting the results to an xml structure and using the xml as an
    array collection. I just don't know how to do the cfc -> xml.
    Any alternative solutions are welcome also. thanks

    Bleh, double posted this due to forum maintenance.

  • Combine Multiple Worksheets into one table

    Hello Everyone!
    I have 2 Excel worksheets within the same workbook. Both have identical tables with almost the same fields except for 2 or 3 different columns in one of the sheets. Currently I have a macro assigned to a button on one of the sheets and I have to click on
    it to combine the 2 sheets. I also have a Pivot Table on one of the sheets which pulls data from the table on that sheet and displays it on the existing sheet.
    I wish to :
    1. Combine (merge) these two sheets into one table on a new worksheet when Excel file is opened rather than clicking on the button.
    2. Once the Excel file is opened, i would like to have the Pivot Table to pull data off the combined sheet and display it next to the combined table. Essentially I would like the Pivot Table to be refreshed with the new data from the Combined table rather
    than from one table.
    Is this possible ?
    I use the following code to combine the two sheets, but I don't know how to proceed further. Can someone please help me with the rest ?? Thanks in advance.
    Here's the code:
    Option Explicit
    Sub Combine()
    Dim J As Integer
    On Error Resume Next
    Sheets(1).Select
    Worksheets.Add
    Sheets(1).Name = "Combined Results"
    Sheets(2).Activate
    Range("A1").EntireRow.Select
    Selection.Copy Destination:=Sheets(1).Range("A1")
    For J = 2 To Sheets.Count
    Sheets(J).Activate
    Range("A1").Select
    Selection.CurrentRegion.Select
    Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
    Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2)
    Next
    End Sub
    The problem with being punctual is, there's nobody there to appreciate it !!!

    Hi,
    This is the forum to discuss questions and feedback for Microsoft Excel, the issue is more related to Excel DEV. I'll move your question to the MSDN forum for Excel
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev&filter=alltypes&sort=lastpostdesc
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Table Combination for SERIALNO Field - 101 Document No

    Dear friends,
           Kindly provide us a table link for the Feild SERIALNO for the given 101 Documentno(MBLNR). The serialNo can be viewed in Migo T.code. Also, Provide us with a Primary Field combination table or FM to Fetch the data for a report.
    Thanks in Advance.
    Moderator message: please do more research before asking, show what you have done when posting.
    Edited by: Thomas Zloch on Feb 14, 2012

    Try this one:
    SELECT T1.CardCode Customer, T1.CardName 'Customer Name', Case T0.InvType WHEN '13' THEN 'INVOICE' WHEN '14' THEN 'CR Memo' END AS 'TYPE', T0.DocEntry AS 'Invoice/CR#', T1.DocCurr AS 'BY',Case WHEN T1.DocCurr = '$' THEN T0.SumApplied ELSE T0.AppliedFC END AS 'Paid Amount', CASE WHEN T1.CashSum > 0 THEN 'Cash' WHEN T1.CreditSum > 0 THEN 'CC' WHEN T1.TrsfrSum > 0 THEN 'WIRE' ELSE 'Check' END AS 'Method', T1.DocNum AS 'RC#', T1.DocDate AS 'Posted' 
    FROM dbo.ORCT T1   INNER JOIN dbo.RCT2 T0 ON T1.DocNum = T0.DocNum  WHERE Month(T1.DocDate) = Month(GetDate()) AND Year(T1.DocDate) = Year(GetDate()) AND T1.JrnlMemo != 'Cancelled' AND T1.NoDocSumSy > 0.02
    Thanks,
    Gordon

  • Question about combining two tables

    I have two tables that I want to combine them together:
    Table A: ID x
    49 3
    127 1
    Table B: ID y
    49 1
    83 2
    127 1
    Expected combined table C: ID x y
    49 3 1
    83 0 2
    127 1 1
    Seems I have to do two out join and them union them together. Any better ways?
    Thanks
    gary

    The tables are not displayed properly. try it again:Use the {noformat}{noformat} tag for that.
    Put it before and after your example.
    So, when you type or paste your formatted code like this:
    {noformat}select *
    from dual;{noformat}
    it will appear as:select *
    from dual;on this forum                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Merging two separate Tables into One - different number of rows

    Hi. I have a problem. Oracle 10.2.0.4.0
    7 years ago when i was learning how to query my teacher told me that is possible to creata some kind of report where results could be combined in 1 view(report) witch in different variable could have different number of rows.
    I just remember that there is needed to use group by function and some join?
    Please help
    In link there is a sample sample view
    I need to combine Table A using D variable with Table B to become Wynik(result)
    Tables create
    CREATE TABLE "TABELA_A" ( A NUMBER,B NUMBER,C NUMBER,D NUMBER ) ;
    INSERT INTO "TABELA_A" (A, B, C, D) VALUES (123, 1, 70, 999)
    INSERT INTO "TABELA_A" (A, B, C, D) VALUES (123, 2, 80, 999)
    INSERT INTO "TABELA_A" (A, B, C, D) VALUES (234, 1, 100, 111)
    INSERT INTO "TABELA_A" (A, B, C, D) VALUES (456, 1, 10, 222)
    CREATE TABLE "TABELA_B" ( D NUMBER,E VARCHAR2(255),F NUMBER ) ;
    INSERT INTO "TABELA_B" (D, E, F) VALUES (999, 'A', 1);
    INSERT INTO "TABELA_B" (D, E, F) VALUES (999, 'B', 1);
    INSERT INTO "TABELA_B" (D, E, F) VALUES (999, 'B', 3);
    INSERT INTO "TABELA_B" (D, E, F) VALUES (999, 'C', 1);
    INSERT INTO "TABELA_B" (D, E, F) VALUES (111, 'A', 1);
    INSERT INTO "TABELA_B" (D, E, F) VALUES (111, 'C', 2);
    And to become result - in picture
    [http://i303.photobucket.com/albums/nn153/katanbutcher/pytanko.jpg?t=1306152636]
    Thank's for help
    Edited by: 860710 on 2011-05-23 05:42
    Edited by: 860710 on 2011-05-23 05:54
    Edited by: 860710 on 2011-05-23 06:07

    Maybe if you follow the instructions mention in this post you may get some help. For example, I wouldn't try to click on the link provided by you.
    SQL and PL/SQL FAQ
    Regards
    Raj

Maybe you are looking for

  • AR Open Items

    Hi All, I would like to know what is the trasaction code for uploading the AR Open Items in FI and Vendor master data. Please help me... Thanx Kelly.

  • Block Site 1.1.8 is not blocking websites entered into Blacklist

    I am using Firefox 31.0 on a Toshiba laptop running Windows 7 Ultimate 64-bit. I added an add-on called Block Site because I keep getting these very aggravating windows opening that I haven't visited and don't want to see such as adcash.com and gacet

  • Need help creating "rubber stamp" logo

    I would like to create what should look like a rubber stamp, to place inside an Indesign document. Something like this (drawn very roughly in Photoshop): However, although I have Illustrator CS4 (Macintosh version) I've never used it and could need s

  • Photoshop CS6 constant 25% CPU Usage with Nvidia card (nvoglv64.dll)

    Hi, i'm using Adobe Photoshop CS6 (Cloud) and have the latest version installed. I experience a high cpu problem when i want to zoom in the picture, then sometimes the cpu load of the CS6 process is constant on 25%. I tried the graphic advanced setti

  • Create a popup custom

    Hi all I am working on user exit. In this, I needed to add a popup where some buttons are present and user choose one and then the control is returned to the user exit. I created this popup with an external report submitted where there was a CALL SCR