How to combine count() queries to tables in different environments?

Hi all,
I've got two tables that have the same schema, but slightly different data. One is a test db, and the other is a model office db (i.e. neither is a production db).
I run these two queries, individually, from within the test db:
select count(cdeSource), cdeSource
from schema1.SomeTable
group by cdeSource
order by cdeSource
select count(cdeSource), cdeSource
from schema1.SomeTable@TheModelOfficeDB
group by cdeSource
order by cdeSource
The column cdeSource can contain a 1 to 1 relationship with another field in the tables, but it can also contain a 1 to many with the other field.
Right now, I need to export each result into a file and then do a compare between the two to find the differences, between the two tables, out of the big results.
Question: How can I combine those two queires into 1, and show only the differences from the "count(cdeSource)" results column?
Thanks.
Edited by: we5inelgr on Jan 29, 2013 5:29 PM

we5inelgr wrote:
Example snippet of results:
Test environment
Count(cdeSource) | cdeSource
2 | "00.01" <---Same as other environment, would like to exclude
6 | "00.09" <---Same as other environment, would like to exclude
16 | "00.50" <---Different count, for same cdeSource. need to include
2 | "00.95" <---cdeSource only found in Test. need to include
2 | "72.1" <---Different count, for same cdeSource. need to include
Model Office environment
Count(cdeSource) | cdeSource
2 | "00.01"
6 | "00.09"
10 | "00.50"
3 | "72.1"
6 | "98.1" <---cdeSource only found in Model Office. need to include
I tried putting "MINUS" in between both queries, and it gives me an error: ORA-00933: SQL command not properly ended.
I tried wrapping that whole query, within a select * from () but gave me a different error: ORA-00907: missing right parenthesis
Other ideas how to combine the two?
Thanks.if & when you use valid syntax, then no errors get thrown.
We can not tell you what you do wrong, since you don't use COPY & PASTE to show us what exactly you do.
SELECT cdeSource, COUNT(cdeSource) FROM TABLE1
MINUS
SELECT cdeSource, COUNT(cdeSource) FROM TABLE1@remote_db;

Similar Messages

  • How to create a view on tables with different keys?

    I have to create a View on:
    Z3PVR: Transparent Table
    BSEG: Cluster Table
    CKIS: Transparent Table
    BKPF: Transparent Table
    RV61A: Structure
    T001: Transparent Table
    All the tables have different "Key Fields" and the structure has no "Key Fields". When i create the view, what do I mention in the "JOIN FIELDS" tab. and how do i create the view with the structure?
    Please advise.

    How to create a view on a Non-Transparent Tables.
    how to create view?
    HELP.. How to create a view with the tables with ALV

  • Spatial overlay queries involving tables with different spatial extents

    We are using GeoMedia Professional 6.1 with an Oracle 10g database. For validating geometry, we use a standard minimum bounding rectangle (MBR) that is fairly tight to our city boundary. Some city departments are requesting that we extend the spatial limits to create a larger MBR for some new features. This will involve using a new SDO_DIMINFO array in the MDSYS.SDO_GEOM_METADATA_TABLE and creating new spatial indexes. It is our intention to leave the existing features "as-is" with the original MBR and spatial indexes. I have done some preliminary testing in GeoMedia and have not run into any issues when doing spatial queries involving features with different MBRs. Spatial intersections, spatial differences and spatial filters seem to complete in a reasonable amount of time, even with large data sets. Does anyone have any experience using different MBRs with Oracle spatial overlay queries? Are there any other potential issues we should be aware of when working with tables that are created with different spatial extents such as performance?

    Luc ... Thank you for supplying the URL for Simon Greener’s website. This article supports information we already received from our GIS software provider.
    With regards to your questions: One of the checks carried out in our “ValidateGeometry” procedure is to ensure that a new or modified geometry is within the bounding rectangle defined by the SDO_DIMINFO. An error is raised if the user tries to add a polygon that is well beyond the city boundary rather than within the prescribed city area. Currently, we do not use different MBR’s as layer extents (there are only a couple of exceptions). We are in the process of conducting system and performance testing to identify potential issues that may be encountered when tables created with expanded upper and lower bounds are used in downstream applications such as intranet/internet web maps. We are still trying to identify any potential “hotspots”.

  • How to show master and detail tables in different pages?

    Hi,
    Can somebody expalin me how to include or bind the master and detail tables to different pages which are included at runtime.
    thnaks,
    Naresh.

    Hello!
    you have ti create a Master/Detail data structure.
    In the first page drag the master table, on the second drag a detail table.
    It should work out of the box. Selecting a record on the master table selects
    the details on the detail table automatically!
    regards,
    Mario Udina

  • How to compare standard texts used in Sapscripts different Environments

    Hello Gurus,
    I need to compare the standards texts found in different environments.
    1. I would like to know if there is a program /Tcode that does this.
    2. In what table are the standard texts kept?
    3. How can I access the contents of another environment?
    Thanks  gurus.
    Parvez

    hii parvez
    standard tables are stored in the table so10
    u can access throu standard prog RSTXFCOM
    RSTXR3TR to transport
    reward points if useful
    regards
    Jaipal

  • How to combine multiple queries!

    I know this is pretty basic, but I'm confused. Basically, I need to extract all data for a given entity from a highly normalized database. There are probably 2 dozen tables which contain data for a given entity that must be queried. However, rather than constructing one single query that merges all of the tables together to come up with one huge rowset/row format, how could I query each table seperately and combine the results of each query into one XML file? Can I create a clob with the first query and then append subsequent queries to that clob? Not sure what to do, and I can't find any good examples.
    Thanks in advance!

    Thanks, but I don't think that's quite what I'm looking for. In a nutshell, this is what I'm doing and this is the problem I'm having:
    1. I set a string equal to a query.
    2. I use xmlgen.getxml to fetch the xml into a clob.
    3. I parse the clob into a DOMDocument.
    The problem occurs with multiple queries. If I follow this same process for 5 different queries, then I have 5 instances of a DOMDocument, each holding a different queries XML. Now, can I put them together? I tried xmldom.makeNode for each DOMDocument, but the nodes are associated with the Document from which they came. I tried cloning each node to disassociate from it's Document, but that didn't seem to work. Even if it did, and I got all of the nodes together, I kept getting a java.lang.ClassCastException for trying xmldom.makeDocument for a node. I'm lost. How can I combine the results of multiple queries into a single DOMDocument instance? It was suggested that use xmlgen.getXML to get multiple queries into multiple CLOBS, then essentially combine the CLOBS together, and finally parse into a DOMDocument as a last step, but that doesn't really leverage DOMs capabilities. At this point, I may have to go down that road...

  • URGENT:HOW TO COMBINE CLUSTER AND TRANSPARENT TABLE..WITHOUT USING FOR ALL

    how can we join bkpf and bseg without using FOR ALL ENTRIES.HOW DO I COMBINE THE 2 TABLES SO THAT I GET BETTER PERFORMANCE.
    START-OF-SELECTION.
    SELECT bukrs belnr gjahr budat FROM bkpf INTO TABLE i_bkpf
    WHERE bukrs = p_bukrs AND "COMPANY CODE
    gjahr = p_gjahr AND "FISCAL YEAR
    budat IN s_budat. "POSTING DATE IN DOC
    IF sy-subrc = 0.
    SELECT bukrs belnr gjahr hkont shkzg dmbtr FROM bseg INTO TABLE
    i_bseg FOR ALL ENTRIES IN i_bkpf
    WHERE bukrs = i_bkpf-bukrs AND "COMPANY CODE
    belnr = i_bkpf-belnr AND "A/CING DOC NO
    gjahr = i_bkpf-gjahr AND "FISCAL YEAR
    hkont = p_hkont. "General Ledger Account"
    IF sy-subrc = 0.
    SELECT bukrs belnr gjahr hkont shkzg dmbtr FROM bseg INTO TABLE
    i_bseg1 FOR ALL ENTRIES IN i_bseg
    WHERE bukrs = i_bseg-bukrs AND "COMPANY CODE
    belnr = i_bseg-belnr AND "A/CING DOC NO
    gjahr = i_bseg-gjahr. "FISCAL YEAR
    ENDIF.
    ENDIF.
    IF NOT i_bseg1[] IS INITIAL.
    LOOP AT i_bseg1.
    IF i_bseg1-hkont = p_hkont AND i_bseg1-shkzg = 'S'.
    v_sumgl = v_sumgl + i_bseg1-dmbtr.
    ELSEIF i_bseg1-hkont = p_hkont AND i_bseg1-shkzg = 'H'.
    v_sumgl = v_sumgl - i_bseg1-dmbtr.
    ELSEIF i_bseg1-hkont NE p_hkont .
    IF i_bseg1-shkzg = 'H'.
    i_bseg1-dmbtr = - i_bseg1-dmbtr.
    ENDIF.
    i_alv-hkont = i_bseg1-hkont.
    i_alv-dmbtr = i_bseg1-dmbtr.
    APPEND i_alv.
    v_sumoffset = v_sumoffset + i_bseg1-dmbtr.
    ENDIF.
    ENDLOOP.
    regards
    Essam.([email protected])

    Hi Friend,
      I see your code.. there is no other way than using for all entries for your situation.. how ever i saw ur code and a small recommandation in the change of code.
    SELECT bukrs belnr gjahr budat FROM bkpf INTO TABLE i_bkpf
    WHERE bukrs = p_bukrs AND "COMPANY CODE
    gjahr = p_gjahr AND "FISCAL YEAR
    budat IN s_budat. "POSTING DATE IN DOC
    IF sy-subrc = 0.
    if not p_hkont is initial.
    SELECT bukrs belnr gjahr hkont shkzg dmbtr FROM bseg INTO TABLE
    i_bseg1 FOR ALL ENTRIES IN i_bkpf
    WHERE bukrs = i_bseg-bukrs AND "COMPANY CODE
    belnr = i_bseg-belnr AND "A/CING DOC NO
    gjahr = i_bseg-gjahr. "FISCAL YEAR
    ENDIF.
    i_bseg[] = i_bseg[]1.
    delete i_bseg where hkont ne p_hkont.
    else.
      Your existing logic...
    endif.
    In this way you can avoide writing two selects on bseg..
    Thanks
    Mahesh

  • How to combine two queries?

    Can you help to combine these two categories so that I can have dynamic pivot table ?
    Thank you,
    IF OBJECT_ID('Temp') IS NOT NULL
    DROP TABLE Temp
    select 'Referrals Received' AS CategoryType,
    'A' AS CategorySort,
    cn.Cntry_Definition as Cntry,
    COUNT(*) AS Cnt,
    SUM(SUM(1)) OVER () AS Total
    INTO Temp
    from  WRAPSIST0.dbo.tblindividual i
    inner join   WRAPSIST0.dbo.tblcase c on c.case_guid = i.case_guid
    inner join  WRAPSIST0.dbo.tblCountry CN on CN.Cntry_Code=c.Cntry_CodeLocation
    inner join  WRAPSIST0.dbo.tblfiscalyear fy on case_createdate between fy_startdate and fy_enddate
    where fy_year = '2014' and casear_code <> 'du' and c.CaseP_Code<>'sv'
    GROUP BY cn.Cntry_Definition
     order by cntry asc
    DECLARE @CountryList varchar(8000),@SQL varchar(max)
    SELECT @CountryList= STUFF((SELECT ',[' + Cntry + ']' FROM Temp FOR XML PATH('')),1,1,'')
    SET @SQL = 'SELECT CategoryType,' + @CountryList + ',Total FROM Temp t 
    PIVOT(SUM(Cnt) FOR Cntry IN (' + @CountryList + '))p'
    EXEC(@SQL)
    IF OBJECT_ID('Prescr') IS NOT NULL
    DROP TABLE Prescr
    select 'Prescreen Completed' AS CategoryType,
    'B' AS CategorySort,
    cn.Cntry_Definition as Cntry,
    COUNT(*) AS Cnt,
    SUM(SUM(1)) OVER () AS Total
    INTO Prescr
    FROM ReportStatistician.dbo.vwEventLog_LatestPSI_SCH t
    inner join  WRAPSIST0.dbo.tblIndividual i on i.Ind_GUID=t.Ind_GUID
    inner join  WRAPSIST0.dbo.tblCase C on C.Case_GUID=i.Case_GUID
    inner join  WRAPSIST0.dbo.tblNationality N on N.Nat_Code=i.Nat_Code
    inner join  WRAPSIST0.dbo.tblCountry CN on CN.Cntry_Code=c.Cntry_CodeLocation
    inner join  WRAPSIST0.dbo.tblfiscalyear fy on t.EventLog_EffectiveDate between fy_startdate and fy_enddate
    where fy_year = '2014' and c.PreS_Code='com'
    GROUP BY cn.Cntry_Definition
     order by cntry asc
    --DECLARE @CountryList varchar(8000),@SQL varchar(max)
    SELECT @CountryList= STUFF((SELECT ',[' + Cntry + ']' FROM Prescr FOR XML PATH('')),1,1,'')
    SET @SQL = 'SELECT CategoryType,' + @CountryList + ',Total FROM Prescr t 
    PIVOT(SUM(Cnt) FOR Cntry IN (' + @CountryList + '))p'
    EXEC(@SQL)
    CREATE TABLE #final
    CategoryType varchar(50),
    CategorySort char(1),
    cntry char(20),
    Total int
    select CategoryType, cntry, Total 
    from #final
    order by CategorySort
    Erdal Huzmeli

    The result of the query looks as following;
    CategoryType
    Kuwait
    Lebanon
    Turkey
    United Arab Emirates
    Yemen
    Total
    Referrals Received
    1
    2
    3
    4
    5
    CategoryType
    Kuwait
    Lebanon
    Turkey
    United Arab Emirates
    Yemen
    Total
    Prescreen Comleted
    6
    7
    8
    9
    10
    I want the query to show the following result if it possible?
    CategoryType
    Kuwait
    Lebanon
    Turkey
    United Arab Emirates
    Yemen
    Total
    Referrals Received
     1
    2
    3
    4
    5
    Prescreen Completed
     6
    7
    8
    9
    10
    Thank you,
    Erdal Huzmeli

  • How to Combine two queries into One

    Hi Gurus,
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    SQL>
    I have following two queries. How I can convert these two queries into one with the same result ?
    Q1
    SELECT id,vdate,vendorname,venddate,vid
    FROM VENDOR
    WHERE processid=32
    AND venddate is null
    AND vid in(select vid from view_vid where type='PDX')
    AND (id,vdate) not in (select id,vdate from vkfl_is where task_id=55)
    AND (id,vdate) in (select id,vidate from market_data where marketed_date is null)
    AND id not in (select id from location)
    Q2
    SELECT id,vdate,vendorname,venddate,vid
    FROM VENDOR
    WHERE processid=20
    AND venddate is null
    AND vid in(select vid from view_vid where type='PBX')
    AND (id,vdate) not in (select id,vdate from vkfl_is where task_id=40)
    AND (id,vdate) in (select id,vidate from market_data where region_date is null)
    AND id not in (select id from location)
    I can UNION these two queries, but, is there any way I can write a single query with which gives me same result as above two queries?
    Any help would be highly appreciated
    Thanks in advance

    Hi,
    You can do something like this, which will be more efficient than a UNION:
    SELECT  id, vdate, vendorname, venddate, vid
    FROM  vendor
    WHERE  (   (    -- Conditions that apply only to q1
                               processid = 32
                AND  vid       IN (SELECT vid FROM view_vid WHERE type = 'PDX')
                AND (id,vdate) NOT IN ( SELECT id, vdate
                                        FROM   vkfl_is
                                        WHERE  task_id = 55
                AND (id,vdate) IN ( SELECT id, vidate
                                    FROM   market_data
                                    WHERE  marketed_date IS NULL
            OR  (  -- Conditions that apply only to q2
                     processid = 20
                AND  vid       IN (SELECT vid FROM view_vid WHERE type = 'PBX')
                AND (id,vdate) NOT IN ( SELECT id, vdate
                                        FROM   vkfl_is
                                        WHERE  task_id = 40
                AND (id,vdate) IN ( SELECT  id, vidate
                                    FROM  market_data
                                    WHERE  region_date IS NULL
                   -- The remaining conditions apply to both q1 and q2
    AND     venddate   IS NULL
    AND     id         NOT IN (SELECT id FROM location)
    I hope this answers your question.
    If not, post  a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to combine two queries in one EXCEL

    hi i got one requirement
    i got one excel sheet  from user which contains two  report s(hoe we know whether it is worknook or not) of  2011 data and now user wants 2012 data .now i icluded jan 2012 to dec 2012 in two reports and sent to user.But user is asking these two reports want to see in one sheet.
    so how can i proceed: if i go for work  book  how can i include these two reports in workbook and here my doubt is if i create a workbook based on  these two querie which name i have to give user.Please help me out on the same.
    Regards,
    Madhu.

    Hi Madhu
    Run one query. Click on a empty space in the excel
    From the BEx Design Toolbar -
    >Insert Analysis Grid -
    > Right click on the Design Item
    Edit the DataProvider.....You can ran same or different query with selection. 
    Save the result
    Check this link for detail....I am also searching for something with screenshot
    Regards
    Anindya
    Edited by: Anindya Bose on Feb 14, 2012 3:04 AM

  • How do i count number of table being used in a view

    Hi All,
    I will be really thankful if anyone please let me know about the count of number of tables being used in a view. I am using Oracle 10g Release 2 on HP-UX(11.31).
    In actual I have to find views in my database with more than 5 table in join.
    Thank you
    Gursimran

    Try :
    select count(*) from dba_dependencies
    where name ='<view name>'
    and owner = '<view owner>'
    and referenced_type= 'TABLE';Example:
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    SQL> show user;
    USER is "HR"
    SQL>
    SQL> drop table t1 purge;
    Table dropped.
    SQL> drop table t2 purge;
    Table dropped.
    SQL> drop table t3 purge;
    Table dropped.
    SQL> drop view v;
    View dropped.
    SQL>
    SQL> create table t1(x int);
    Table created.
    SQL> create table t2(y int);
    Table created.
    SQL> create table t3(z int);
    Table created.
    SQL> create view v as select x,y,z from t1,t2,t3;
    View created.
    SQL>
    SQL> connect / as sysdba
    ConnectÚ.
    SQL> alter session set nls_language=english;
    Session altered.
    SQL>
    SQL> select count(*) from dba_dependencies
      2  where name ='V'
      3  and owner = 'HR'
      4  and referenced_type= 'TABLE';
      COUNT(*)
             3
    SQL>Edited by: P. Forstmann on 26 juil. 2010 17:45

  • How to combine two queries using Web application Designer

    Hello experts...
    This should be a simple request.
    I have two existing queries that I simply want to display on the same template. What is the best way to do this?
    To add more complexity to it, if there is a result value that I want to pull from each of them, how can this be done so that I can add the results of the two into one total?
    Any help that you can provide is greatly appreciated. Thanks

    Hi,
    Displaying the existing queries on the same template is very simple... Drag and drop to web items... for ex we will drag and drop two analysis web item...
    Create 2 data providers and assign it to the web items... each dataprovider is in turn assigned to two existing queries...
    I am not sure about the result value to be pulled from each of them...
    Regards,
    Kishore

  • How to combine 2 the same tables from 2 different databases

    We have made 2 databases company1 and company2
    Both databases contains the same tables
    Now we want to make a report with server reporting services. The report must give us information from the 2 databases.
    We use the following query:
    SELECT     '501'as divisie, GRV_DebtorOutstanding2.[Debtor code] AS Debiteur, GRV_DebtorOutstanding2.cmp_name AS Naam, SUM(GRV_DebtorOutstanding2.[Outstanding Amount]) AS Saldo,
                          GRV_DebtorOutstanding2.blokkade, GRV_Debtors.City
    FROM         [501].dbo.GRV_DebtorOutstanding2 INNER JOIN
                          [501].dbo.GRV_Debtors ON GRV_DebtorOutstanding2.[Debtor code] = GRV_Debtors.[Debtor code]
    WHERE     (GRV_DebtorOutstanding2.blokkade = 'B')
    GROUP BY GRV_DebtorOutstanding2.[Debtor code], GRV_DebtorOutstanding2.cmp_name, GRV_DebtorOutstanding2.blokkade, GRV_Debtors.City
    ORDER BY Debiteur
    when we use the same query to select the data of the other database in the same query it doesn't work. I have tried it with the command Union All
    But it crashes,
    please help, to fix it

    Hi Robert,
    According to your description, you have created two same databases. When you run the same query for the second database, it doesn’t work.
    In your scenario, since databases are the same and the query for first database can work fine, it should also work when query the second database using the same query. When you create second dataset, please check if you have used a correct datasource
    which is second database. Then try to run the query again. If issue persists, please share the error message around the time when you query the second database.
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • How to combine sql queries of two different data models of a single RDF

    Hi All,
    Greetings.
    I am on a task to get  the sql query of a seeded report(Accounting Rules Report) with RDF named RAXARL.rdf
    The RDF consists of 3 data models which consist of a sql query each and they are running fine individually.But I want all those three to be combined in a single SQL Query so that I can use it running  a report in apex.
    Can anyone help me do this? I am able to find a solution for this.
    Thanks in advance,
    Bhaskar.

    Hi Bhaskar,
    To get the SQL behind the report, run it with the Enable Trace option enabled (disable it after you get it).
    Octavio

  • How to move data in the table to different database ?

    I'm currently having some problem with moving some of my data from devlopment db to production db. Currently i'm having 2 dev. db and i would like to combine the data in the table into 1 prod. db. Can anyone pls tell me, is it possible to do so. Please tell me the solution on how this can be done, if you guys know.
    Thanks in advance.

    Hi,
    create a database_link from your
    PROD db to each of the DEV dbs.
    then insert into table (select * from
    table@dev_db1)
    insert into table (select * from table@dev_db2)
    HTH
    Detlev
    null

Maybe you are looking for

  • Can i turn in my ipod for a new photo or video?

    I purchased my ipod this past summer for 300 dollars. it is a 20 GB. does apple have any trade in policies or a replacement system? i kno there would probably be a fee added.

  • Hard drive issues...running out of ideas...opinions?

    Hello everyone! Let me start by saying that I love all of my Apple products. I've been able to use an iPod mini, another iPod, an iPhone, a Powerbook G4 and a MacBook with no daily or otherwise recurring issue; however, the reason I now have a MacBoo

  • How to convert mkd mdf file to regular file format

    I am pretty new to video converting.. I just wander if anyone know which software could convert these 2 file mkd, mdf format to something else, like avi or mpg format. I am using mini mac G4. os x 10.4. pls help

  • New ipod, can't get it to download from PC.

    I have just purchased my first iPod (60GB). Have sucessfully loaded the software onto my Toshiba laptop, incerted a CD and imported the songs, but when I connect the actual iPod through the USB cable, the iPod flashes 'Do not disconnect'. Nothing els

  • Inserting an Image on mouse clicked HELP

    Hi. I', trying to make a Tic tac toe game(if you do not understand please run this programme). The thing I want to happen is: the user clicks over a "sqare" and when mouse is released the image (X or O) appears on that position. I can't get my progra