Collections:
Filtering Out Duplications in the Returning Rows in SQL Server
How To Filter Out Duplications in the Returning Rows in SQL Server?
✍: 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:
CREATE TABLE fyi_team (first_name VARCHAR(8), last_name VARCHAR(8)) GO INSERT INTO fyi_team VALUES ('John', 'Gate') GO INSERT INTO fyi_team VALUES ('John', 'Russell') GO INSERT INTO fyi_team VALUES ('John', 'Seo') GO INSERT INTO fyi_team VALUES ('John', 'Gate') GO INSERT INTO fyi_team VALUES ('James', 'Gate') GO INSERT INTO fyi_team VALUES ('Peter', 'Gate') GO INSERT INTO fyi_team VALUES ('John', 'Gate') GO SELECT * FROM fyi_team GO first_name last_name John Gate John Russell John Seo John Gate James Gate Peter Gate John Gate SELECT DISTINCT * FROM fyi_team GO first_name last_name James Gate John Gate John Russell John Seo Peter Gate SELECT DISTINCT last_name FROM fyi_team Gate Russell Seo
Remember that * in select list represents all columns.
⇒ Group Functions in Query Statements in SQL Server
⇐ Using SELECT Statements on Views in SQL Server
⇑ Using SELECT Statements and GROUP BY Clauses in SQL Server
2016-10-26, 1317🔥, 0💬
Popular Posts:
How To Replace Given Values with NULL using NULLIF() in SQL Server Transact-SQL? Sometime you want t...
How To Change the Name of a Database User in SQL Server? If you want to change the name of an existi...
Can You Drop an Index Associated with a Unique or Primary Key Constraint in Oracle? You can not dele...
How To List All Stored Procedures in the Current Database in SQL Server Transact-SQL? If you want to...
How To Format DATETIME Values to Strings with the CONVERT() Function in SQL Server Transact-SQL? SQL...