Tracking Down Duplicates : COUNT « Aggregate Functions « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Aggregate Functions » COUNT 
Tracking Down Duplicates
        
mysql> CREATE TABLE authors (
    ->   authID int(11NOT NULL auto_increment PRIMARY KEY ,
    ->   authName varchar(60),
    ->   ts timestamp
    -> );
Query OK, rows affected (0.01 sec)

mysql>
mysql>
mysql>
mysql>
mysql> INSERT INTO authors VALUES (1,'Tom','2004-12-02 18:36:51'),
    ->                              (2,'Jack','2004-12-02 18:36:51'),
    ->                              (3,'Jane','2004-12-02 18:36:51'),
    ->                              (4,'Amy','2004-12-02 18:36:51'),
    ->                              (5,'Bob','2004-12-02 18:36:51'),
    ->                              (6,'Race','2004-12-02 18:36:51'),
    ->                              (7,'Green','2004-12-02 18:36:51');
Query OK, rows affected (0.00 sec)
Records: 7  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> SELECT authName, COUNT(*AS cnt
    -> FROM authors
    -> GROUP BY authName
    -> HAVING cnt>1;
Empty set (0.00 sec)

mysql>
mysql> drop table authors;
Query OK, rows affected (0.00 sec)

mysql>
mysql>

   
    
    
    
    
    
    
    
  
Related examples in the same category
1.COUNT([DISTINCT] { | *})
2.Get the number of items for each type of wood
3.Get the number of woods for each type of item
4.Counting
5.How many times did drivers travel more than 200 miles in a day?
6.COUNT and GROUP BY
7.Count by group
8.COUNT(expr) doesn't count NULL values is useful when producing multiple counts from the same set of values.
9.The different forms of COUNT( ) can be very useful for counting missing values
10.Put the COUNT( ) expression in a HAVING clause instead.
11.Queries counting duplicate records have the following form
12.Counting and Identifying Duplicates
13.Count number of rows containing duplicated names
14.To see which names are duplicated in the cat_mailing table, use a summary query that displays the non-unique v
15.Eliminating Duplicates from a Query Result
16.Removing Duplicates of a Particular Row
17.Count duplicate records
18.How many days did Suzi drive?
19.How many messages were sent by each message sender
20.How many states did the United States consist of at the beginning of the 20th century?
21.Or to count weekend versus weekday trips
22.Count each value and see which one is most common
23.Generating Frequency Distributions
24.Relative frequency distributions
25.Counting Missing Values
26.Count them directly using SUM(ISNULL(score)).
27.Count the total number of rows
28.Categorizing Non-Categorical Data
29.Total number of the table vs unique values count
30.To produce a count-per-author summary that includes even authors with no books in the book table, use a LEFT J
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.