SELECT ALL SQL Server Syntax Example: SELECT ALL argument T-SQL Example

SELECT ALL SQL Server Syntax Example: SELECT ALL argument T-SQL Example

Purpose: – Illustrates the for the .

Syntax: SELECT [ ALL | DISTINCT ]
[TOP ( expression ) [PERCENT] [ WITH TIES ] ]
select_list
[ INTO new_table ]
[ FROM { table_source } [ ,…n ] ]
[ WHERE search_condition ]
[ GROUP BY ]
[ HAVING search_condition ]
– ALL indicates that duplicates are included in search results

View Other SQL Server Syntax Examples

-- SELECT ALL 
-- PURPOSE: ALL indicates that duplicates are to be included - ALL is the default 
-- and DISTINCT is the other option  
-- SYNTAX: SELECT [ ALL | DISTINCT ] 
--			[TOP ( expression ) [PERCENT] [ WITH TIES ] ] 
--			 select_list 
--			[ INTO new_table ] 
--			[ FROM { table_source } [ ,...n ] ] 
--			[ WHERE search_condition ] 
--			[  GROUP BY  ] 
--			[ HAVING search_condition ] 
 
 
CREATE TABLE people(
     ID          int,
     name        varchar (20),
     height      int )
 GO
 
 
 
 
 INSERT INTO people (ID, name, height) VALUES (1,  'Paul', 72)
 GO
 
 INSERT INTO people (ID, name, height) VALUES (2,  'John', 69)
 GO
 
 INSERT INTO people (ID, name, height) VALUES (3,  'Steve', 75)
 GO
 
 INSERT INTO people (ID, name, height) VALUES (4,  'Steve', 65)
 GO
 
-- ALL includes duplicates
 SELECT ALL name FROM people;
 GO
 
-- DISTINCT excludes duplicates
 SELECT DISTINCT name FROM people;
 GO
 
 
 drop table people;
 
 GO

Sample Output for SELECT ALL Example

Folder