Tutorial by Examples

Steam has a games under $10 section of their store page. Somewhere deep in the heart of their systems, there's probably a query that looks something like: SELECT * FROM Items WHERE Price < 10
This example uses the Car Table from the Example Databases. SELECT * FROM Cars WHERE TotalCost IN (100, 200, 300) This query will return Car #2 which costs 200 and Car #3 which costs 100. Note that this is equivalent to using multiple clauses with OR, e.g.: SELECT * FROM Cars WHERE TotalCos...
See full documentation on LIKE operator. This example uses the Employees Table from the Example Databases. SELECT * FROM Employees WHERE FName LIKE 'John' This query will only return Employee #1 whose first name matches 'John' exactly. SELECT * FROM Employees WHERE FName like 'John%' Ad...
SELECT * FROM Employees WHERE ManagerId IS NULL This statement will return all Employee records where the value of the ManagerId column is NULL. The result will be: Id FName LName PhoneNumber ManagerId DepartmentId 1 James Smith 1234567890 NULL 1 SEL...
Unlike the WHERE clause, HAVING can be used with aggregate functions. An aggregate function is a function where the values of multiple rows are grouped together as input on certain criteria to form a single value of more significant meaning or measurement (Wikipedia). Common aggregate function...
The following examples use the Item Sales and Customers sample databases. Note: The BETWEEN operator is inclusive. Using the BETWEEN operator with Numbers: SELECT * From ItemSales WHERE Quantity BETWEEN 10 AND 17 This query will return all ItemSales records that have a quantity that is gr...
SELECT * FROM Employees This statement will return all the rows from the table Employees. Id FName LName PhoneNumber ManagerId DepartmentId Salary Hire_date CreatedDate ModifiedDate 1 James Smith 1234567890 NULL 1 1000 01-01-2002 0...
You can also combine several operators together to create more complex WHERE conditions. The following examples use the Employees table: Id FName LName PhoneNumber ManagerId DepartmentId Salary Hire_date CreatedDate ModifiedDate 1 James Smith 1234567890 NULL ...
Orders Table CustomerIdProductIdQuantityPrice12510013220014150021450356700 To check for customers who have ordered both - ProductID 2 and 3, HAVING can be used select customerId from orders where productID in (2,3) group by customerId having count(distinct productID) = 2 Return value:...
Will select records in TableName that have records matching in TableName1. SELECT * FROM TableName t WHERE EXISTS ( SELECT 1 FROM TableName1 t1 where t.Id = t1.Id)

Page 1 of 1