Misc SQL Server SELECT Examples

SELECT - All columns

Return all columns.

SELECT 
   *  
FROM Courses

SELECT - Return first 10 rows

Run a SQL Select statement and limit the number of rows returned. Useful when you are not sure of how to limit the recordset to be returned and you only want to return a few rows to do some initial analysis.

	SELECT TOP 10
  course_designater , 
  course_name       , 
  employee_inactivating 
FROM Courses  

SELECT - Count rows in table

Returns a count of the total number of rows in a table.

	SELECT COUNT(*) from Courses

SELECT - Joining tables

Join two SQL Server tables together.

SELECT 
  a.[course_name]      , 
  b.[class_start_date] ,
  b.[class_end_date] 

FROM [dbo].[Courses]  a 
JOIN [dbo].[Classes]  b 
     ON a.[course_designater] = b.[course_designater_fk]

WHERE a.[course_name] LIKE '%Perl%'
 Collapse All    Expand All
Custom Search

SQL Server Information and Resources