Collections:
Filerting out Duplications in Returning Rows in MySQL
How To Filter Out Duplications in Returning Rows in MySQL?
✍: FYIcenter.com
If there are duplications in the returning rows, and you want to remove the duplications, you can use the keyword DISTINCT in the SELECT clause. The DISTINCT applies to the combination of all data fields specified in the SELECT clause. The tutorial exercise below shows you how DISTINCT works:
mysql> CREATE TABLE fyi_team (first_name VARCHAR(8),
last_name VARCHAR(8));
mysql> INSERT INTO fyi_team VALUES ('John', 'Gate');
mysql> INSERT INTO fyi_team VALUES ('John', 'Russell');
mysql> INSERT INTO fyi_team VALUES ('John', 'Seo');
mysql> INSERT INTO fyi_team VALUES ('John', 'Gate');
mysql> INSERT INTO fyi_team VALUES ('James', 'Gate');
mysql> INSERT INTO fyi_team VALUES ('Peter', 'Gate');
mysql> INSERT INTO fyi_team VALUES ('John', 'Gate');
mysql> SELECT * FROM fyi_team;
+------------+-----------+
| first_name | last_name |
+------------+-----------+
| John | Gate |
| John | Russell |
| John | Seo |
| John | Gate |
| James | Gate |
| Peter | Gate |
| John | Gate |
| John | Gate |
+------------+-----------+
8 rows in set (0.00 sec)
mysql> SELECT DISTINCT * FROM fyi_team;
+------------+-----------+
| first_name | last_name |
+------------+-----------+
| John | Gate |
| John | Russell |
| John | Seo |
| James | Gate |
| Peter | Gate |
+------------+-----------+
5 rows in set (0.00 sec)
mysql> SELECT DISTINCT last_name FROM fyi_team;
+-----------+
| last_name |
+-----------+
| Gate |
| Russell |
| Seo |
+-----------+
3 rows in set (0.04 sec)
⇒ What Are Group Functions in MySQL
⇐ Using SELECT Statements in Views in MySQL
2018-01-06, 2144🔥, 0💬
Popular Posts:
Where to find SQL Server database server tutorials? Here is a collection of tutorials, tips and FAQs...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...
How To Fix the INSERT Command Denied Error in MySQL? The reason for getting the "1142: INSERT comman...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...