SQL distinct statement

The SQL distinct statement is used to search for a distinct value from many duplicate values in the database. SQL count distinct values and returns records that occur more than once. Let’s know how to count distinct values in SQL.

/ ***** All duplicate names will be shown once ***** /

SELECT DISTINCT name 
FROM Employees;

/ ***** All duplicate age will be shown once ***** /

SELECT DISTINCT age 
FROM Employees;

/ ***** All duplicate salary will be shown once ***** /

SELECT DISTINCT salary 
FROM Employees
WHERE employeeID >= 5;

/ ***** All duplicate name will be shown once with order by ***** /

SELECT DISTINCT name 
FROM Employees
ORDER BY name;

SQL Count Distinct Values

If you want to count distinct values then you can use count function for that. Know how to count distinct values in SQL.

/ ***** It will count all distinct values ***** /

SELECT COUNT(DISTINCT name) 
FROM Employees;

SQL Keywords

We have some keywords of SQL available, which are used most commonly. Let’s know what those keywords are and what they mean.

NoKeywordsDescription
1CREATEIt is used to create a database and table
2CREATE DATABASEIt is used to create a database only
3CREATE TABLEIt is used to create a table
4DELETEIt is used to delete record from the table
5DROPIt is used to delete a column, database, and table
6DROP COLUMNIt is used to delete a column in the table
7DROP TABLEIt is used to delete a table
8FOREIGN KEYIt is used to join two tables together
9JOINIt is used to join the tables
10UPDATEIt is used to update the record in the table

SQL Frequently Asked Questions

We have answers to some questions that people search on the Internet every day. Let’s know what those questions are and what their answers are.

What does SQL mean?
SQL stands for Structured Query Language

How to extract data from the database?
Using the “SELECT” statement.

How to update data in the database?
Using the “UPDATE” statement.

How to delete data in the database?
Using the DELETE statement.

How to insert new data in the database?
Using the INSERT INTO statement.

how do you select a column name?
Using the “SELECT MyName FROM Mytable” statement.

how do get the full table data?
Using the “SELECT * FROM Mytable” statement.

how do get different or distinct values?
Using the “SELECT DISTINCT ” statement.

how to sort the result?
Using ORDER BY keyword.

how to select a value within a range?
Using the BETWEEN keyword.

how to search for a specific pattern?
Using the LIKE keyword.

how to create a table in the database?
Using the CREATE TABLE keyword.

What does TRIM() Function?
It Removes spaces from a string.

What does the CONCAT() Function?
It Adds two strings together.

What does the LEN() Function?
It returns the length of the string.

What does the REPLICATE() Function?
It repeats the same string.

Related: 20 best examples of SQL like operator