SQL Query Find Row Differences

Hello All!
This will most likely be a super-easy question and solution for some one.  Here is my scenario.
2 tables (Table_1, Table_2)
3 columns (A, B, C)
Table_1 has fewer records than Table_2, so I want to find the records in Table_2 that are not in Table_1I don't care to find records that are in Table_1 and not in Table_2
I will make the comparison only with Column A
For simplicity sake, lets say Table_1 has 10 total rows and Table_2 has 15 total rows.  It should only find the 5 rows that are in Table_2 and not in Table_1.  Therefore, if I add the number of records found in Table_2 to the total records in Table_1, then I should have at least the same amount of records in Table_1 and Table_2, if not more.  Also, is there a way where I can insert the row differences found into a 3rd "staging" table?
Example provided below.
Table_1
A | B | C
1 | blahblah | something
2 | blahblah | something
3 | blahblah | something
4 | blahblah | something
5 | blahblah | something
Table_2
A | B | C
1 | blahblah | something
3 | blahblah | something
5 | blahblah | something
6 | blahblah | something  <=== Difference
7 | blahblah | something  <=== Difference
In reality, there are millions of records in both tables.  I have a workaround for this, but it would require me to do this...Export the results from both Table_1 and Table_2.  Open both results in Excel and run a macro to find the difference.  Once I find the difference, I save it and import the results into the 3rd "staging" table.
Any help would be great!  Thanks!

SKP wrote:
But the op has asked for comparison with column A  only
Right, I missed that. Then you are right, we can use NULL adjusted NOT EXISTS:
with table_1 as(
                select 1 A,'ABC' B , 'XYZ' C from Dual UNION ALL
                select 2 A,'ABD' B , 'WYZ' C from Dual UNION ALL
                select 3 A,'ABE' B , 'VYZ' C from Dual
    table_2 as (
                select 1 A,'ABC' B , 'XYZ' C from Dual UNION ALL
                select 2 A,'ABD' B , 'WYZ' C from Dual UNION ALL
                select 3 A,'ABE' B , 'VYZ' C from Dual UNION ALL
                select 4 A,'ABF' B , 'UYZ' C from Dual UNION ALL
                select 5 A,'ABG' B , 'TYZ' C from Dual UNION ALL
                select null A,'ABG' B , 'TYZ' C from Dual
select  *
  from  table_2
  where not exists(
                   select  1
                     from  table_1
                     where table_1.a = table_2.a
                        or (table_1.a is null and table_2.a is null)
SY.
Message was edited by: Solomon Yakobson

Similar Messages

  • SQL Query Single Row not working

    My workflow contain a Query Single row activity. I have added a where clause in Arabic which is not working. If I remove the Arabic condition its working.
    Is there something to do with the server?
    My server is windows 2008 R2 Server.
    The same workflow is running perfectly on another identical environment.
    Thanks for any valuable suggestions,
    Nith

    Hi Sastry,
    Connection to the database is trough Pivotal, I have tried ODBC connection as well but same error
    The instruction at "0x005d53e0" refereced memory at "0x00000014'. The memory could not be "read".
    With ODBC I have always compilation error saying
    Query Engine Error: '42000:[Microsoft][ODBC SQL Server Driver][SQL server] Incorrect syntax near the keyword 'SELECT'. '.
    but even the simple select statment is showing the error.
    Do you think the error is with Drivers???
    Regards
    Stefan

  • SQL Query find month/year and then calculate difference from start date

    Hi All,
    Assume I have a table with a column Start_Date. I like to know how we can build a query to so we can find the end of the month date based on the start_ date and then calculate the difference
    For example lets say we have a date 12/06/2014 and now based on this we should get the end of the month date which is 30/06/2014. Now we can get the difference which is 18 days.
    Thanks

    Hi Jaggy99,
    According to your description, you need to get the date difference between a given date and the last day of that month, right?
    In this case, please try the query below.
    SELECT GETDATE() AS [CURRENTDAY], DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0)) AS [LASTDAY],
    DATEDIFF(DAY, GETDATE (), DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0))) AS [DIFFERENCE]
    Regards,
    Charlie Liao
    TechNet Community Support

  • Difference between values in 2 rows in SQL query

    I have to find the difference between inventory onhand in the same store in week1 and week2.
    I tried to do it in one "select" query something like :
    SELECT store_id, ( suppose to be function that calculates difference) FROM my_table WHERE week=week1 or week=week2 GROUP BY store_id
    however I have no idea how to find the difference between the valuues in two separate rows.
    thanks in advance.

    If you have only two weeks in your data. This can work.
    SQL> select * from emp
      2  /
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7839 KING PRESIDENT 17-NOV-81 5000 10
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
          7876 ADAMS CLERK 7788 12-JAN-83 1100 20
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
          8888 KING PRESIDENT 17-NOV-81 7000 10
          9999 ADAMS CLERK 7788 12-JAN-83 7000 20
    16 rows selected.
    SQL> select ename, max(sal) - min(sal) diff
      2  from emp
      3  group by ename
      4  /
    ENAME            DIFF
    ADAMS 5900
    ALLEN               0
    BLAKE               0
    CLARK               0
    FORD                0
    JAMES               0
    JONES               0
    KING 2000
    MARTIN              0
    MILLER              0
    SCOTT               0
    SMITH               0
    TURNER              0
    WARD                0
    14 rows selected.
    SQL> Cheers
    Sarma.

  • How to find a dependent row in the all tables using single SQL query

    hi all,
    I have created some table with master and some dependent tables.I want to mark a (row)tuple as inactive in master so that corresponding child records also should be marked as inactive.
    So i decided to mark the master and dependent records as inactive starting from master table and traverse to child tables.
    So I need SQL query to fetch all dependend records to the row(marked row in the master ) from the master table and dependent rows from the child row and to mark as flag inactive.
    can anybody help me out to build this query or any other way to mark flag as inactive ?
    Regards
    punithan

    You can find dependant tables from ALL_CONSTRAINTS, e.g:
    SQL> CREATE TABLE m (id INT PRIMARY KEY, flag VARCHAR2(1) NOT NULL);
    Table created.
    SQL> CREATE TABLE d1 (m_id REFERENCES m, flag VARCHAR2(1) NOT NULL);
    Table created.
    SQL> CREATE TABLE d2 (m_id REFERENCES m, flag VARCHAR2(1) NOT NULL);
    Table created.
    SQL> SELECT table_name, owner, status
      2  FROM   all_constraints c
      3  WHERE  c.constraint_type = 'R'
      4  AND    ( c.r_owner, c.r_constraint_name ) IN
      5         ( SELECT owner, constraint_name
      6           FROM   user_constraints
      7           WHERE  table_name = 'M'
      8           AND    constraint_type IN ('U','P') );
    TABLE_NAME                     OWNER                          STATUS
    D2                             WILLIAMR                       ENABLED
    D1                             WILLIAMR                       ENABLED
    2 rows selected.There is no SQL command to apply all updates in one go, if that's what you were looking for.
    AFAIK the word "tuple" is for mathematics and relational theory, and does not refer to a physical row in a database.

  • How to find duplicate row in sql query?

    Hi All,
    Please solve my query, find duplicate row and how to count its. your suggestion would be greatly appreciated.

    You can use group by and having.
    SQL> WITH t
      2       AS (SELECT       LEVEL id
      3                 FROM   DUAL
      4           CONNECT BY   LEVEL <= 5
      5           UNION ALL
      6           SELECT       LEVEL + 2
      7                 FROM   DUAL
      8           CONNECT BY   LEVEL <= 3)
      9  SELECT   *
    10    FROM   t;
            ID
             1
             2
             3
             4
             5
             3
             4
             5
    8 rows selected.
    SQL> WITH t
      2       AS (SELECT       LEVEL id
      3                 FROM   DUAL
      4           CONNECT BY   LEVEL <= 5
      5           UNION ALL
      6           SELECT       LEVEL + 2
      7                 FROM   DUAL
      8           CONNECT BY   LEVEL <= 3)
      9  SELECT     id, COUNT (*)
    10      FROM   t
    11  GROUP BY   id
    12    HAVING   COUNT (*) > 1;
            ID   COUNT(*)
             3          2
             4          2
             5          2
    SQL>

  • SQL Query to find the Delta between 2 rows

    Can the below be possible? If so can you help me writing aSQL Query to do so…
    I have data in spreadsheet which is pulled off from the database (data from more than one table with joins); send it to the different teams. They will check the data n update the spreadsheet if necessary and send it back to me.
    I have to find the changes and update the database from the provided spreadsheet accordingly. Changes can be on different columns on each set of row.
    Example:
    DataFrom
    ServerName
    Branch_Name
    Application_Name
    Server Status
    Application_Status
    App_Environment
    Tier
    SQL Query
    abcdef
    app
    adp
    Deployed
    Deployed
    Production
    silver
    Excel
    abcdef
    app
    adp
    Deployed
    Deployed
    Development
    Bronze
    DataFrom
    ServerName
    Branch_Name
    Application_Name
    Server Status
    Application_Status
    App_Environment
    Tier
    SQL Query
    Hijkl
    app
    adp
    Deployed
    Deployed
    Production
    Gold
    Excel
    Hijkl
    app
    Dep
    Deployed
    Deployed
    Production
    Gold
    DataFrom
    ServerName
    Branch_Name
    Application_Name
    Server Status
    Application_Status
    App_Environment
    Tier
    SQL Query
    Xzy
    app
    Dep
    Deployed
    Deployed
    Production
    Silver
    Excel
    Xzy
    App
    Dep
    Deployed
    Deployed
    Development
    Silver
    Above scenario is an example what I am look to do with sql script? Opinions/queries accepted…
    There are 1200+ rows to compare it manually which is a pain.
    Thanks.

    Columns are different, when the contain multiple distinct values.
    SELECT COUNT(DISTINCT Name) ,
    COUNT(DISTINCT GroupName) ,
    COUNT(*)
    FROM HumanResources.Department;
    Without a concise and complete example (table DDL and sample data insert statements), it's hard to tell what the correct solution could be..
    DECLARE @Sample TABLE ( SetID INT, ServerID INT, ApplicationID INT );
    INSERT INTO @Sample
    VALUES ( 1, 1, 1 ),
    ( 1, 1, 1 ),
    ( 2, 1, 1 ),
    ( 2, 1, 2 ),
    ( 3, 1, 1 ),
    ( 3, 2, 1 );
    WITH Evaluate AS
    SELECT SetID,
    COUNT(DISTINCT ServerID) AS Servers,
    COUNT(DISTINCT ApplicationID) AS Applications
    FROM @Sample
    GROUP BY SetID
    SELECT S.*,
    CASE WHEN E.Servers != 1 THEN 1 ELSE 0 END AS ServersDifferent,
    CASE WHEN E.Applications != 1 THEN 1 ELSE 0 END AS ApplicationsDifferent
    FROM @Sample S
    INNER JOIN Evaluate E ON S.SetID = E.SetID
    ORDER BY S.SetID;

  • Write the sql query to find largest value in row wise without using   great

    write the sql query to find largest value in row wise without using
    greatest fuction?

    Another not so good way, considering you want greatest of 4 fields from a single record:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (Select 100 col1,200 col2,300 col3,400 col4 from dual
      2  union select 500,600,700,800 from dual
      3  union select 900,1000,1100,1200 from dual
      4  union select 1300,1400,1500,1600 from dual
      5  union select 1700,1800,1900,2000 from dual
      6  union select 2100,2200,2300,2400 from dual
      7  union select 2800,2700,2600,2500 from dual
      8  union select 2900,3000,3100,3200 from dual)
      9  SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) Max_value
    10  FROM
    11  (SELECT (CASE WHEN col1_col2 > col2_col3 THEN col1_col2 ELSE col2_col3 END) col1,
    12         (CASE WHEN col2_col3 > col3_col4 THEN col2_col3 ELSE col3_col4 END) col2,
    13         (CASE WHEN col3_col4 > col4_col1 THEN col3_col4 ELSE col4_col1 END) col3
    14  FROM
    15  (SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) col1_col2,
    16         (CASE WHEN col2 > col3 THEN col2 ELSE col3 END) col2_col3,
    17         (CASE WHEN col3 > col4 THEN col3 ELSE col4 END) col3_col4,
    18         (CASE WHEN col4 > col1 THEN col4 ELSE col1 END) col4_col1
    19* FROM t))
    SQL> /
    MAX_VALUE
           400
           800
          1200
          1600
          2000
          2400
          2800
          3200
    8 rows selected.
    SQL> Edited by: AP on Sep 21, 2010 6:29 AM

  • Query to find the difference between the last date and the second to the last date

    Hi all,
    Hope all is well.
    I am working on the following problem because I am trying to improve my MS SQL skills. But I am stuck at the moment and I wonder if you could provide some assistance please. Here is the issue:
    Table 1: Dividends
    divId
    ExDate
    RecordDate
    PayDate
    Amount
    Yield
    symId
    1
    2013-02-19
    2013-02-21
    2013-03-14
    0.23
    0.00000
    3930
    2
    2012-11-13
    2012-11-15
    2012-12-13
    0.23
    0.00849
    3930
    3
    2012-08-14
    2012-08-16
    2012-09-13
    0.20
    0.00664
    3930
    4
    2012-05-15
    2012-05-17
    2012-06-14
    0.20
    0.00662
    3930
    5
    2012-02-14
    2012-02-16
    2012-03-08
    0.20
    0.00661
    3930
    6
    2011-11-15
    2011-11-17
    2011-12-08
    0.20
    0.00748
    3930
    7
    2011-08-16
    2011-08-18
    2011-09-08
    0.16
    0.00631
    3930
    8
    2011-05-17
    2011-05-19
    2011-06-09
    0.16
    0.00653
    3930
    9
    2011-02-15
    2011-02-17
    2011-03-10
    0.16
    0.00594
    3930
    10
    2010-11-16
    2010-11-18
    2010-12-09
    0.16
    0.00620
    3930
    11
    2010-08-17
    2010-08-19
    2010-09-09
    0.13
    0.00526
    3930
    12
    2010-05-18
    2010-05-20
    2010-06-10
    0.13
    0.00455
    3930
    13
    2010-02-16
    2010-02-18
    2010-03-11
    0.13
    0.00459
    3930
    Table 2: Tickers
    symId
    Symbol
    Name
    Sector
    Industry
    1
    A
    Agilent Technologies Inc.
    Technology
    Scientific & Technical Instruments
    2
    AA
    Alcoa, Inc.
    Basic Materials
    Aluminum
    3
    AACC
    Asset Acceptance Capital Corp.
    Financial
    Credit Services
    4
    AADR
    WCM/BNY Mellon Focused Growth ADR ETF
    Financial
    Exchange Traded Fund
    5
    AAIT
    iShares MSCI AC Asia Information Tech
    Financial
    Exchange Traded Fund
    6
    AAME
    Atlantic American Corp.
    Financial
    Life Insurance
    7
    AAN
    Aaron's, Inc.
    Services
    Rental & Leasing Services
    8
    AAON
    AAON Inc.
    Industrial Goods
    General Building Materials
    9
    AAP
    Advance Auto Parts Inc.
    Services
    Auto Parts Stores
    10
    AAPL
    Apple Inc.
    Technology
    Personal Computers
    11
    AAT
    American Assets Trust, Inc.
    Financial
    REIT - Office
    12
    AAU
    Almaden Minerals Ltd.
    Basic Materials
    Industrial Metals & Minerals
    I am trying to check the last date (i.e. max date) and also check the penultimate date (i.e. the second to the last date).  And then find the difference between the two (i.e. last date minus penultimate
    date).
    I would like to do that for each of the companies listed in Table 2: Tickers.  I am able to do it for just one company (MSFT) using the queries below:
    SELECT
    [First] = MIN(ExDate),
    [Last] = MAX(ExDate),
    [Diff] = DATEDIFF(DAY, MIN(ExDate), MAX(ExDate))
    FROM (
    SELECT TOP 2 Dividends.ExDate
    FROM Dividends, Tickers
    WHERE Dividends.symId=Tickers.symId
    AND Tickers.Symbol='MSFT'
    ORDER BY ExDate DESC
    ) AS X
    Outputs the following result:
    First
    Last
    Diff
    2012-11-13
    2013-02-19
    98
    But what I would like instead is to be able to output something like this:
    Symbol
    First
    Last
    Diff
    MSFT
    2012-11-13
    2013-02-19
    98
    AAN
    2012-11-13
    2012-12-14
    1
    X
    2012-11-13
    2012-12-14
    1
    Can anyone please let me know what do I need to add on my query in order to achieve the desired output?
    Any help would be greatly appreciated.
    Thanks in advance. 

    Could you try this?
    create table Ticker (SymbolId int identity primary key, Symbol varchar(4))
    insert into Ticker (Symbol) values ('MSFT'), ('ORCL'), ('GOOG')
    create table Dividend (DividendId int identity, SymbolId int constraint FK_Dividend foreign key references Ticker(SymbolId), ExDate datetime, Amount decimal(18,4))
    insert into Dividend (SymbolId, ExDate, Amount) values
    (1, '2012-10-1', 10),
    (1, '2012-10-3', 1),
    (1, '2012-10-7', 7),
    (1, '2012-10-12', 2),
    (1, '2012-10-23', 8),
    (1, '2012-10-30', 5),
    (2, '2012-10-1', 10),
    (2, '2012-10-6', 1),
    (2, '2012-10-29', 7),
    (3, '2012-10-1', 22),
    (3, '2012-10-3', 21),
    (3, '2012-10-7', 3),
    (3, '2012-10-12', 9)
    WITH cte
    AS (SELECT t.Symbol,
    d.ExDate,
    d.Amount,
    ROW_NUMBER()
    OVER (
    partition BY Symbol
    ORDER BY ExDate DESC) AS rownum
    FROM Ticker AS t
    INNER JOIN Dividend AS d
    ON t.SymbolId = d.SymbolId),
    ctedate
    AS (SELECT Symbol,
    [1] AS maxdate,
    [2] AS penultimatedate
    FROM cte
    PIVOT( MIN(ExDate)
    FOR RowNum IN ([1],
    [2]) ) AS pvtquery),
    cteamount
    AS (SELECT Symbol,
    [1] AS maxdateamount,
    [2] AS penultimatedateamount
    FROM cte
    PIVOT( MIN(Amount)
    FOR RowNum IN ([1],
    [2]) ) AS pvtquery)
    SELECT d.Symbol,
    MIN(MaxDate) AS maxdate,
    MIN(penultimatedate) AS penultimatedate,
    DATEDIFF(d, MIN(penultimatedate), MIN(MaxDate)) AS numberofdays,
    MIN(MaxDateAmount) AS maxdateamount,
    MIN(penultimatedateAmount) AS penultimatedateamount,
    MIN(MaxDateAmount) - MIN(penultimatedateAmount) AS delta
    FROM ctedate AS d
    INNER JOIN cteamount AS a
    ON d.Symbol = a.symbol
    GROUP BY d.Symbol
    ORDER BY d.Symbol
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers.
    Thanks!
    Aalam | Blog (http://aalamrangi.wordpress.com)

  • Dynamic SQL Query to Find Special Characters in Table columns

    Hi,
    I am new to OTN FORUMS.
    I am trying to find the columnsi of a table which have special characters in them.
    I am planning on using this query
    select ' select INSTR('||column_name||', chr(0))
    from '||table_name||'where INSTR('||column_name||', chr(0)) >0' from user_tab_columns
    where table_name='Account'
    and spool the output to run as a script.
    Is this the right way or do u suggest any modifications to the query?
    Thanks in advance.

    Hi,
    I think your basic approach is right. Since you can't hard-code the table- or column names into the query, you'll need dynamic SQL.
    Instead SQL-from-SQL (that is, writing a pure SQL query, whose output is SQL code), you could do the whole job in PL/SQL, but I don't see any huge advantage either way.
    When you say "Special character<b>s</b>", do you really mean "one given special character" (in this case, CHR(0))?
    Will you ever want to search for multiple special characters at once?
    What if table foo has a column bar, and in 1000 rows of foo, bar contains CHR (0). Do you want 1000 rows of output, each showing the exact position of the first CHR(0)? If the purpose is to look at theese rows later, shouldn't you include the primary key in the output? What if CHR(0) occurs 2 or more times in the same string?
    If you'd rather have one row of output, that simply says that the column foo.bar sometimes contains a CHR(0), then you could do something like this:
    SELECT     'foo',     'bar'
    FROM     dual
    WHERE     EXISTS (
                SELECT  NULL
                FROM       foo
                WHERE       INSTR ( bar
                            , CHR (0)
                        ) > 0
                );

  • SQL Query updateable report with row selector. Update process.

    I have a SQL Query updateable report with the row selector(s).
    How would I identify the row selector in an update process on the page.
    I would like to update certain columns to a value of a select box on the page.
    Using the basic:
    UPDATE table_name
    SET column1=value
    WHERE some_column=some_value
    I would need to do:
    UPDATE table_name
    SET column1= :P1_select
    WHERE [row selector] = ?
    Now sure how to identify the [row selector] and/or validate it is checked.
    Thanks,
    Bob

    I don't have the apex_application.g_f01(i) referenced in the page source...In the page source you wouldn't find anything by that name
    Identify the tabular form's checkbox column in the page(firebug/chrome developer panel makes this easy)
    It should be like
    &lt;input id=&quot;...&quot; value=&quot;&quot; type=&quot;checkbox&quot; name=&quot;fXX&quot; &gt;we are interested in the name attribute , get that number (between 01 and 50)
    Replace that number in the code, for instance if it was f05 , the code would use
    apex_application.g_f05
    --i'th checked record' primary keyWhen you loop through a checkbox array, it only contains the rows which are checked and it is common practice to returns the record's primary key as the value of the checkbox(available as the the i'th array index as apex_application.g_f05(i) , where i is sequence position of the checked row) so that you can identify the record.

  • Exists (SQL query returns at least one row) condition with MAX on 10.2.0.4

    I just wanted to note this on the forum..
    I'm using Apex 3.0.1.00.08
    My DEV environment has just been upgraded from 10g version 10.2.0.2.0 to 10.2.0.4.0.
    I created the following process to select some values into some items on my Form page.
    select  MAX(STAT_YEAR+1)
          , pcd.pct_id
          , pcd.stat_type_id
          , pcd.stat_period_type_id
          , pcd.measurement_id
    into    :P11_STAT_YEAR
          , :P11_PCT_ID
          , :P11_STAT_TYPE_ID
          , :P11_STAT_PERIOD_TYPE_ID
          , :P11_MEASUREMENT_ID
    from  plant_commodity_data pcd
        , stat_type stt
    where pcd.STAT_TYPE_ID = stt.STAT_TYPE_ID
      and pcd.pct_id = :P0_PCT_ID
      and stt.stat_type = 'PRD'
    group by pcd.pct_id
          , pcd.stat_type_id
          , pcd.stat_period_type_id
          , pcd.measurement_id;The process should run conditionally if there was at least one row to select...
    So I copied the SQL into the Process condition, removed the "into" section and set the condition type to be "Exists (SQL query retruns at least one row) ...
    select  MAX(STAT_YEAR+1)
          , pcd.pct_id
          , pcd.stat_type_id
          , pcd.stat_period_type_id
          , pcd.measurement_id
    from  plant_commodity_data pcd
        , stat_type stt
    where pcd.STAT_TYPE_ID = stt.STAT_TYPE_ID
      and pcd.pct_id = :P0_PCT_ID
      and stt.stat_type = 'PRD'
    group by pcd.pct_id
          , pcd.stat_type_id
          , pcd.stat_period_type_id
          , pcd.measurement_id;This worked perfectly until the DEV environment was upgraded from 10g version 10.2.0.2.0 to 10.2.0.4.0.
    The condition would fire even if there were no rows returning.
    I pasted the condition code into SQL Developer connected to the DEV (10.2.0.4.0) environment and it returned no rows.
    To solve the problem, I removed the MAX.
    You can test this using this code if you have access to the two versions... select  MAX(1)
          , sysdate
          , 'Gus'
    from  dual
    where 1 = 2
    group by sysdate, 2Now I know the MAX isn't required in the condition as I'm just trying to find out if any rows exist, but it was there as I copied the code in... I was just wondering why this happened between 10.2.0.2.0 and 10.2.0.4.0?
    Gus..

    Hi Gus,
    try to execute
    select count(*) from dual where exists (select  MAX(1)
          , sysdate
          , 'Gus'
    from  dual
    where 1 = 2
    group by sysdate, 2)in SQL Developer. The above statement is generated by APEX for an "Exists (SQL query retruns at least one row)". Can't test it, because I don't have a 10.2.0.4.0 at hand.
    Does SQL Developer now show the same behavior?
    Patrick
    My APEX Blog: http://www.inside-oracle-apex.com
    The APEX Builder Plugin: http://builderplugin.oracleapex.info/
    The ApexLib Framework: http://apexlib.sourceforge.net/

  • Sql query union double rows

    Hi,
    i have a problem with my sql query.
    I need the difference from query 2 - query 1.
    the red marked row should be ignored because its already in table 1.
    Union compares all colums not just the first 3.
    Here's a screen of the problem:
    http://c60.img-up.net/?up=screenoracskt6.JPG
    thx for all

    Hi,
    Welcome to the forum!
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
    Explain how you get those results from that data.
    Always say what version of oracle you're using.
    user6754335 wrote:
    Hi,
    i have a problem with my sql query.
    I need the difference from query 2 - query 1.
    the red marked row should be ignored because its already in table 1.
    Union compares all colums not just the first 3.That's right; UNION compare all the columns selected. If you're only interested in 3 of the columns, then only select those 3.
    If you need to display more columns, but not where all 3 of them match, then the best way is probably an outer join; but there are lots of other ways, including NOT EXISTS, NOT IN, and MINUS (in a sub-query).
    Here's a screen of the problem:
    http://c60.img-up.net/?up=screenoracskt6.JPG
    Post anything relevant on this site.

  • How to find the backend  SQL query of the JSP page in OIC

    Does anybody how the best way to find the backend SQL QUERY of OIV JSP page?

    How To Generate Trace Files in in HTML/JSP (using Profile Option)
    •     • Note: This requires proper responsibility to set SQL Initialization statement using Profile option.      
         Step 1.     Login to the desired Form application.     
         Step 2.     Select +Profile >> System ('Find System Profile Values' screen will pop up)     
         Step 3.     Check 'User' and Type in the Username (in which the account for that user will be trace)     
         Step 4.     Type 'Initialization%' in the Profile box and Hit 'Find' (Click here for preview.)     
         Step 5.     In the User box, type the following statement and Hit 'Save' (Click here for preview)
         BEGIN FND_CTL.FND_SESS_CTL('','','TRUE','TRUE','','ALTER SESSION SET TRACEFILE_IDENTIFIER = TESTING MAX_DUMP_FILE_SIZE = 5000000 EVENTS ='||''''||' 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12'||'''');END;     
         Note:     specify any name you like to identify your trace, in this case, testing is the end name on the trace. You can also specify the amount of data allowable to be in the trace, in this case, 5000000 is the amount set. Make sure you hit 'Save' afterwards.[Quotes in the statement are all 'Single' quotes.]
              specifying TRACEFILE_IDENTIFIER value is mandatory when setting up the trace using the above profile option value
         Step 6.     Login to HTML / JSP page with username/password and start your flow. (Everything you do once login to HTML / JSP will get trace.)     
         Step 7.     Logout of HTML / JSP application once you completed with your flow.      
         Step 8.     Go back to the Profile option in the Form application and delete the Initialization SQL statement, and Hit 'Save'.     
         Step 9.     Log in to the database server or login server and retrieve your trace file.
         Identify and retrieve the trace file using the tracefile_identifier specified in Step 5.
         In this case the tracefile_identifier is “TESTING”. (Click here for Trace file locations) *     
         Note:     If you need to regenerate your trace or tracing a new flow, then repeat Step 1 to Step 8. To avoid self-confusion, choose a different name for your trace identifier everytime you set to trace.     
         Step 10.     See TKPROF section on how to format trace file into readable text.
         Trace Options Definition
         No Trace          Tracing is not activated
         Activities will not get traced.
         Regular Trace
         (Level 1)          Contains SQL, execution statistics, and execution plan.
         Provides execution path, row counts as well as produces smallest flat file.
         Trace with Binds
         (Level 4)          Regular Trace plus value supplied to SQL statement via local variables.
         Trace with Waits
         (Level 8)          Regular Trace plus database operation timings that the SQL waited to have done in order to complete, i.e. disk access.
         Trace with Binds and Waits
         (Level 12)          Regular trace with both waits and binds information.
         Contains the most complete information and will produce the largest trace file.
    ****Send me an email to [email protected],I will share the document with you.

  • How to find using SQL query application deployed on win 7 machines with SCCM 2012 server or user installed manually.

    Hi,
    how to find using SCCM SQL query,  application deployed on win 7 machines with SCCM 2012 server or user/technician installed manually. Please let me know.

    Thanks, is it not possible via any script also?
    Like Torsten said, how can you tell the difference between CM12 installed applications and locally installed? Once you can answer that, then you can write report.
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

Maybe you are looking for

  • EX60 will not register to CUCM 8.6(2)

    Hello,      I am trying to register a new EX60 to a CUCM 8.6(2) server, but the provisioning continually fails.  IP connectivity is verified, and both the server and endpoint configurations are correct based on this document:  http://www.cisco.com/c/

  • Slow throughput Ironport S370 Proxy CPU 100%

    We have a cluster of 3 x Ironport S370's all running 7.7.0-753 The throughput is really poor we have a 500Mbps Internet connection which at it's peak is only getting to 120Mbps as the Ironports don't seem to be able to handle the traffic. The Proxy C

  • Returning XML. Client.jar not properly created

    Hi. I'm trying to deploy a web service that has some methods that receive Document as parameter and return Document as result type. Weblogic generates a client.jar that don't have all the needed classes, like, LiteralCodec, and many others. Anybody k

  • No Messages in Mail.App

    Can anyone help me? For the last 2 days, I have been getting the red notification symbol in the dock icon, but when I click on it, there are no messages there. I have then had to go to my .Mac account on Safari to see them. Please cam you tell me wha

  • I was trying to download cs2 free verson but, the serial number given comes back invalid.  Is there a new

    I was trying to download cs2 free version but, the serial number given comes back invalid.  Is there a new one?