Count1) with Count (*) Comparison: If your data table does not have a primary key, COUNT (1) than COUNT (*Fast If there is a primary key, then the primary key (the Federated primary key) as the count condition is also more than count (*) to be quick if your table has only one field then count (*) is the fastest. COUNT (*) Count (1) Compare the two. The main or count (1) corresponds to the data field. If Count (1) is a clustered index, ID, that must be count (1) fast. But the difference is very small. Because Count (*), automatically optimizes the specified field to that one. So there's no need to count (?), with Count (*), SQL will help you to complete the count of optimizations: count (*The total number of rows in the returned table includes null rows, but count (column name) returns the total number of all rows except null in the table (columns with default values will also be counted). Distinct the column name, the result will be the result of dropping the value null and repeating the data--------------------------------------------------------------------------------------------------------------- -examples are shown below: SQL>CREATE TABLE Test2 ( 3Ename VARCHAR2 (Ten), 4Sal Number (4) 5 ); The table is created. SQL> INSERT INTO Test values ('Fxe1', -); has been created1line. SQL> INSERT into Test (ename) VALUES ('Fxe2'); has been created1line. SQL> INSERT into Test (ename) VALUES ('fxe3'); has been created1line. SQL> INSERT into Test (ename) VALUES ('fxe4'); has been created1line. SQL> INSERT INTO Test values ('fxe5', the); has been created1line. SQL> INSERT INTO Test values ('Fxe6', the); has been created1line. SQL>Select* fromtest; Ename SAL---------- ----------Fxe1 -fxe2 fxe3 fxe4 fxe5 theFxe6 theSQL>SelectCOUNT (*) fromtest; COUNT (*) ----------6SQL>SelectCount (Sal) fromtest; COUNT (SAL)----------3SQL>SelectCOUNT (distinct Sal) fromtest; COUNT (distinctsal)------------------2SQL>SelectDistinct Sal fromtest; SAL---------- the -
- Count (1) and Count (*) Comparison:
- If your data table does not have a primary key, then Count(1) is faster than count(*)
- If there is a primary key, then the primary key (the Federated primary key) as the count condition is also faster than count(*)
- If your table has only one field, then count(*) is the quickest.
- Count (*) Count (1) comparison of the two. The data field that corresponds to count (1) is mostly still.
- If count(1) is a clustered index, ID, that must be count(1) fast. But the difference is very small.
- Because count(*), automatically optimizes the specified field to that one. So there is no need to count(?), with count(*), SQL will help you to complete the optimized
- Count Detailed:
- Count (*) The total number of rows that are returned in the table will include a value of NULL the line, however Count (column name) removes the returned table NULL The total number of all rows except those with default values will also be counted.
- distinct column name, the resulting result will be the drop value of NULL and repeat the data after the results
- ---------------------------------------------------------------------------------------------------------- ------
- Examples are shown below:
- Sql> Create table test
- 2 (
- 3 ename VARCHAR2 (10),
- 4 sal Number (4)
- 5);
- The table is created.
- sql> Insert into test values(' fxe1 ' , 90);
- 1 rows have been created.
- sql> Insert into test (ename) values(' Fxe2 ') ;
- 1 rows have been created.
- sql> Insert into test (ename) values(' Fxe3 ');
- 1 rows have been created.
- sql> Insert into test (ename) values(' fxe4 ');
- 1 rows have been created.
- sql> Insert into test values(' fxe5 ' , 80);
- 1 rows have been created.
- sql> Insert into test values(' fxe6 ', 80);
- 1 rows have been created.
- sql> Select * from test;
- Ename SAL
- ---------- ----------
- FXE1 90
- Fxe2
- Fxe3
- Fxe4
- Fxe5 80
- Fxe6 80
- sql> Select count(*) from test;
- COUNT (*)
- ----------
- 6
- sql> Select count(sal) from test;
- COUNT (SAL)
- ----------
- 3
- sql> Select count(distinct sal) from test;
- COUNT (distinctsal)
- ------------------
- 2
- sql> Select distinct sal from test;
- SAL
- ----------
- 80
- 90
The difference between count (1) and COUNT (*) in Oracle