Why this query can remove duplicates?

Why this query can remove duplicates? Can someone give me detailed explanation?

Thank you
select salary from employees union select salary from employees;

Hello

See the docs.

' Example of the UNION
The following statement combines the results of two queries with the UNION operator which eliminates duplicates of selected lines.
"This statement shows that you must match the data type (using the function TO_CHAR) when the columns do not exist in one or the other table"

http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/queries004.htm#i2054381

Edit

Here's another interpretation of your question:

http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1224636375004

Published by: hoek on October 22, 2009 17:40

Tags: Database

Similar Questions

  • Why this code give me duplicate data

    HII, all the
    Why this code give me duplicate data
    SELECT (G.NAME_1 ||' '||G.NAME_2||' '||G.NAME_3||' '||G.NAME_4) AS NAME,
                  R.RES_NUM
    FROM    GUST G , RESERVATION R,ROOM_DETAILS S,ROOMS RR
    WHERE   G.RES_NUM = R.RES_NUM
    AND     R.RES_NUM = S.RES_NUM
    AND     RR.OCCUPIED = 'Y'
    RES_NUM
    --------
    1282
    1282
    1282
    1282
    1280
    1280
    1280
    1280
    1281
    1281
    1281
    1281
    1310
    1310
    1310
    1310
    
    16 rows selected

    Try this:

    SELECT DISTINCT (G.NAME_1 ||' '||G.NAME_2||' '||G.NAME_3||' '||G.NAME_4) AS NAME,
                  R.RES_NUM
    FROM    GUST G , RESERVATION R,ROOM_DETAILS S,ROOMS RR
    WHERE   G.RES_NUM = R.RES_NUM
    AND       R.RES_NUM = S.RES_NUM
    AND       RR.OCCUPIED = 'Y'
    
  • Why this query produces no output?

    Why this query produces no output?
    select * from
    (
    SELECT 40 as startvalue, (24 * 60)*(To_Date('00:40', 'HH24:MI') - To_Date('00:00', 'HH24:MI')) as c
    FROM dual di
    ) q
    where q.c = q.startvalue

    And just to show that it works if round you...

    SQL> ed
    Wrote file afiedt.buf
    
      1  select * from
      2  (
      3  SELECT 40 as startvalue, round((24 * 60)*(To_Date('00:40', 'HH24:MI') - To_Date('00:00', 'HH24:MI')),0) as c
      4  FROM dual di
      5  ) q
      6* where q.c = q.startvalue
    SQL> /
    
    STARTVALUE          C
    ---------- ----------
            40         40
    

    I certainly wouldn't say using TRIM as PS has suggested. TRIM is a string function, not a digital function.

  • Can't understand why this query returns multiple lines with the same data

    Hi all
    I am a relative novice and self-taught when it comes to SQL. I wrote a query to our reporting tool that returns multiple rows, and I can't understand why. I know that I can use the SELECT DISTINCT option, but it really slows the execution when I do. I'd really rather understand if I can change the code to avoid the multiples. This is the query. I've included a few statements in italics to help explain the break. Any ideas?

    SELECT MATSITE, MATPONUM, FIRSTRECPTDATE
    Of
    Subquery that concludes the first date on which purchase orders have been implemented with ACK State
    (SELECT ACKSTAT. PONUM AS 'ACKPONUM', (MIN (ACKSTAT. CHANGEDATE)) AS 'FIRSTACKDATE '.
    OF PZMAX. POSTATUS ACKSTAT
    WHERE (ACKSTAT. STATE = 'ACK') AND (ACKSTAT.ORGID ='CGSALTUS)
    GROUP OF ACKSTAT. PONUM),
    Subquery that concludes the first reception against a purchase order transaction for purposes of comparison
    (SELECT TRANS. PONUM AS "MATPONUM", TRANS. SITEID AS 'MATSITE', (MIN (TRANS. TRANSDATE)) AS 'FIRSTRECPTDATE '.
    OF PZMAX. MATRECTRANS TRANS
    WHERE (TRANS.ORGID ='CGSALTUS) AND (TRANS. HOUR > =: startDate and TRANS. TRANSDATE < =: endDate)
    TRANS GROUP. SITEID, TRANS. PONUM)
    WHERE
    (ACKPONUM = MATPONUM AND FIRSTRECPTDATE < FIRSTACKDATE) OR (NOT EXISTS (SELECT 1 FROM PZMAX. POSTATUS ACKSTAT2 WHERE (ACKSTAT2. PONUM = MATPONUM) AND (ACKSTAT2. STATE = 'ACK') AND (ACKSTAT2.ORGID ='CGSALTUS)))

    The where the instruction is intended to find when one of two conditions exists. ((1) received happened before the command either in ACK or 2) a reception that's happened, but the purchase order is never in ACK State. It seems that this second condition that creates multiple lines.

    Any thoughts will be appreciated geratly.

    Dave Teece
  • Stupid old backpacker (me) cannot understand why this query returns 1 row

    Hi all

    In reference to {: identifier of the thread = 2456973}, why do
    select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
    , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
    from emp group by job;
    only 1 rank and not 1 for each task? In fact, I had to test it myself to believe.

    It returns the data as if the query were
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)
    Using only a single aggregate (count or sum) returns 1 row per job, as expected

    John Stegeman wrote:
    It returns the data as if the query were

    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
    from emp group by job)
    

    Exactly the point ;-)

    It seems that Oracle actually do, a group of 'double' in the same operation.
    Attend plans to explain in this example:

    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3  from scott.emp group by job;
    
        CLERKS  SALESMANS
    ---------- ----------
             0          0
             0          0
             0          0
             0          4
             4          0
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1697595674
    
    ---------------------------------------------------------------------------
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  HASH GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------
    

    And compare it to the one with the double aggregates:

    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3  from scott.emp group by job;
    
        CLERKS  SALESMANS
    ---------- ----------
             4          4
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 417468012
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    There are GROUP BY hash and SORT GLOBAL times.

    It is really unnecessary to an aggregate on an aggregate - if two aggregates are used "in the same group level.
    Sum() aggregates are used on an already aggregated value, so it doesn't look like Oracle which actually cures like 'first do the internal aggregate using the group specified by and then do the external aggregation on the result with any group.'

    Look at this example where I combine aggregates "double" with "single" aggregates:

    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS2
      4       , count(*) COUNTS
      5  from scott.emp group by job;
    
        CLERKS  SALESMANS SALESMANS2     COUNTS
    ---------- ---------- ---------- ----------
             4          4          1          5
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 417468012
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    When you mix "doubles" and "single" aggregates, Oracle decides that unique aggregates belong to the 'outer' aggregation
    SALESMAN2 did a count on the aggregated work column which is the result of the 'internal' group by - so only 1.
    The count (*) is also the result of the aggregation of the 'internal '.

    I don't know if it's documented or if it is an 'effect' of internal code used for GROUPING SETS or the internal code used to enable the analytical functions like this:

    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3       , sum(count(decode(job, 'CLERK', 1, null))) over () CLERKS2
      4       , sum(count(decode(job, 'SALESMAN', 1, null))) over () SALESMANS2
      5  from scott.emp group by job;
    
        CLERKS  SALESMANS    CLERKS2 SALESMANS2
    ---------- ---------- ---------- ----------
             0          0          4          4
             4          0          4          4
             0          0          4          4
             0          0          4          4
             0          4          4          4
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 4115955660
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  WINDOW BUFFER      |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   SORT GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    Personally, I think that I would have preferred if Oracle has raised an error on this "double aggregation" and therefore require me to write this way (if it's the result I wanted):

    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)
    

    I don't really see a good use case for aggregations of 'double'-, but rather that he could give you undetected bugs in your code, if you happen to do double aggregation without noticing.

    Interesting thing to know ;-)

  • Why this query SQLLite returns the same all the time?

    Hello

    I use a search box to accept a query on three columns and am page before based on the last record, which in this case is Run Baby Run by Loopy

    I know for a fact that the database has a song inside by Loopy called Straight Down the Line, so this should at least be showing that. But it does is display the same songs again.

    Can someone explain the error in my logic here?

    SELECT * WHERE DiscID AS "loopy %" songs or artist LIKE 'loopy %' or AS "loopy %" title AND artist > = 'LOOPY' COLLATE NOCASE Title > = 'Run Baby Run' COLLATE NOCASE ORDER BY artist COLLATE NOCASE ASC, title COLLATE NOCASE ASC LIMIT 20

    Thanks for taking a peek.

    This is a forum for AS3, not SQL - etc., which may explain the slow Pickup on your ad.  While someone might offer something at some point, you should try to find a forum where they discuss SQL programming, which could mean going out of the domain of Adobe.  The closest thing I can think that would be a forum in the Adobe forums game...

    http://forums.Adobe.com/community/Dreamweaver/server_side

  • Why this query gives me wrong

    Hello

    My java file, I get the data in this format 18-11-2010 0:00:00

    So I used the query in this way

    select distinct to_char (USAGEDATE, ' yyyy-mm-dd hh: mm :) from testsummary where USAGEDATE BETWEEN 2010-10-18 0:00:00 and 18-11-2010 0:00:00)


    Help, please

    query is incorrect and needs to read

    Select distinct to_char (USAGEDATE, 'yyyy-mm-dd hh24:mi:ss')
    of testsummary
    where USAGEDATE BETWEEN to_date ("2010-10-18 0:00:00 ',' yyyy-mm-dd hh24:mi:ss'") and to_date ('18-11-2010 0:00:00 ',' yyyy-mm-dd hh24:mi:ss')

    ----------------------
    Sybrand Bakker
    Senior Oracle DBA

  • That means 1e9 and why this query does not work?

    What does 1e9? Someone has links to documentation on this oracle? And why I get this error?
    SQL> select segment_name,(bytes/1e9) AS size from dba_segments where segment_name='MSG_MASTER';
    select segment_name,(bytes/1e9) AS size from dba_segments where segment_name='MSG_MASTER'
                                       *
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected

    SIZE is a keyword - so if you want the name of the column size then use 'SIZE' else give it a different name

    Try dividing by other exponentials, then you'll see how: 1e0 1e1 (div 1), (div by 10), 1e2 :-) etc

    Mette

    Published by: mettemusens on 2009-05-12 16:02

  • Why this query does not work on the CF when it works fine on MYSQL?

    Subject says it all. I can run it through console mysql and get the result that I need, but when I place it inside a cfquery that he will not treat.

    SET @saldo = 20000;
    SELECT
    IF (Co.transtipo=0,@saldo:[email protected],@saldo:=@saldo+t.transmonto),
    @saldo: = @saldo - t.transmonto.
    t.TransID,
    t.cuentaid,
    t.operacionid,
    t.fechatrans,
    t.voucher,
    t.cheque,
    t.transtitular,
    t.transmonto,
    t.transdetalle,
    t.modificado,
    Co.transtipo,
    Co.Operacion
    OF cuentastrans t
    LEFT JOIN cuentasoperacion co ON t.operacionid = co.operacionid
    WHERE the t.cuentaid = 7
    ORDER BY t.fechatrans ASC

    Fixed, coldfusion must be labeled with 'AS' of the expressions in the opposite case he used to index the column.

  • the option remove duplicates has been removed!

    I have just been advised by apple to use this option to remove duplicate songs - the option has been removed. Why?

    Hello

    You can always find the duplicates. It was move to file > library > show duplicate items.

    Jim

  • How to remove duplicates in my Lightroom Catalog?

    I have merged an old Lightroom Catalog in my Lightroom hand catalogue and accidentally created duplicate images, thousands of them (sometimnes, geometry), I suppose I must have completed the process before, foregotten and not deleted catalogs I merged after that I've merged them... then go back and redo the process... thus creating duplicates.

    My problem is I want to remove duplicates without losing the edited versions. only those that I have meged in.  The file has a lot of images which is not duplicated, so I can't start the process again?

    You can remove duplicates of Lightroom is removing recognizes them in the grid view.

    However, there are a few Plugins available. Here's a Journal http://www.lightroomfanatic.com/tutorials/advanced/finding-duplicate-images-lightroom-cata /

    Find and eliminate duplicate Images in Lightroom | Lightroom training Laura shoe, tutorials and tips

    Let us know if that helps.
    Concerning

    Assani

  • whenever I select any folder or any icon in my computer win 7 I get a popup to remove this icon why this error comes how can I solve this problem pls help me

    whenever I select any folder or any icon in my computer win 7 I get a popup to remove this icon why this error comes how can I solve this problem pls help me

    Hello

    1. don't you make changes to the computer until the problem occurred?

    2. What is the exact error message do you get?

    I suggest you try the steps mentioned below and check if it helps.

    Method 1: Start your system in safe mode and check if the same problem occurs.

    http://Windows.Microsoft.com/en-us/Windows-Vista/start-your-computer-in-safe-mode

     

    Method 2 If the issue does not exist in Mode safe mode then try to put your computer in a clean boot state.

    By setting your boot system minimum state helps determine if third-party applications or startup items are causing the problem.

     

    How to troubleshoot a problem by performing a clean boot in Windows Vista or Windows 7:
    http://support.Microsoft.com/kb/929135

    Note: After the boot minimum troubleshooting step, follow step 7 in the link provided to return the computer to a Normal startup mode.

    Follow these steps to reset the computer to start as usual:

    (a) click on start toreduce this top that i, type msconfig.exe in the Start Search box and press ENTER.

    If you are prompted for an administrator password or for confirmation, type your password, or click continue.

    (b) under the general tab, click the Normal startup option, and then click OK.

    (c) when you are prompted to restart the computer, click restart.

    Method 3:

    Also scan your computer from the Microsoft Security Scanner, which would help us to get rid of viruses, spyware and other malicious software.

    The Microsoft Security Scanner is a downloadable security tool for free which allows analysis at the application and helps remove viruses, spyware and other malware. It works with your current antivirus software.

    http://www.Microsoft.com/security/scanner/en-us/default.aspx

    Note: The Microsoft Safety Scanner ends 10 days after being downloaded. To restart a scan with the latest definitions of anti-malware, download and run the Microsoft Safety Scanner again.

    Hope this information is useful.

  • How can I remove duplicate calendars displayed in my list of calendar on my MAC?

    How can I remove duplicate calendars displayed in my list of calendar on my MAC?

    OS X Version of El 10.11.6 (15-1004)

    MacBook Pro (17-inch, mid 2010)

    Intel Core i5 to 2.53 GHz

    4 GB 1067 MHz DDR3

    Macintosh HD

    alexmike,

    Using iCloud? If so, use iCloud: Apple Advanced calendar and troubleshooting iCal - supported

    If this is not the case, what calendars are duplicated?

  • How can I remove duplicates in Photos massively?

    I not only have duplicates in iPhoto and photos, but also in the pictures. In iPhoto, I remove duplicates, why not in the Photos?

    You can certainly - or program will do it for you and two require third-party software - for Photos of some of the programs tested and safe are

    PowerPhotos

    PhotoSweeper for Photos

    Duplicate Annihilator for Photos

    LN

  • Removing duplicates, I usually have to remove the song duplicate twice to make it disappear. Why?

    When you remove duplicate songs, I usually have to remove the song duplicate twice to make it disappear. Why?

    When I delete the duplicate song it pops up again. When I erase it a second time he remains missing.   After the first removal, he reappeared with a little cloud in an arrow down. Once I have remove that she remains missing.

    Is it possible that I can delete a song in one operation?

    iTunes 12.3.3 on Mac Pro Tower

    Looks like you have an iCloud music library, Subscribe to Match iTunes Apple music (or both).  The first time, you probably delete the local copy of the song file (stored on the storage of your computer).  But the song still in your iCloud library, so it appears in your list of music library with the cloud with the arrow symbol (which you can click to download it again).  You can still play the song streaming from iCloud.  The second time, you delete the song completely within your music to iCloud library.

    You can see the distinction if you right click on a song (which is stored locally) in iTunes.  On the shortcut menu that appears, there are two separate, Remove Download and deletecommands.  Remove Download removes the local copy of the song file, but keeps the song in your music to iCloud libraryDelete deletes the song completely, with a single action.

Maybe you are looking for