SQL

Start Here Glossary WHERE INSERT (Create) SELECT (Read) UPDATE DELETE Join Tables Sub Query Limit Records SQL Injection SSMS Meta Data Sum TABLE Apostrophe Date Identity
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

SQL : WHERE

2018-03-03

WHERE Operators

--Equal
SELECT * FROM z_robsTestTable WHERE primaryid = 1

--Not equal
SELECT * FROM z_robsTestTable WHERE primaryid <> 1
SELECT * FROM z_robsTestTable WHERE primaryid != 1

--Greater Than/Less Than Or Equal
SELECT * FROM z_robsTestTable WHERE primaryid > 3
SELECT * FROM z_robsTestTable WHERE primaryid >= 3
SELECT * FROM z_robsTestTable WHERE primaryid < 3
SELECT * FROM z_robsTestTable WHERE primaryid <= 3

--Range of Values (Can be number, string, or date.)
SELECT * FROM z_robsTestTable WHERE primaryid BETWEEN 2 AND 5

--Opposite. Everything here can be opposite with NOT
SELECT * FROM z_robsTestTable WHERE NOT primaryid = 1

WHERE LIKE wildcards

--city starting with letter S
SELECT * FROM z_robsTestTable WHERE City LIKE 's%';

 -- "road" anywhere in string
SELECT * FROM z_robsTestTable WHERE address1 like '%road%' 

--first 2 characters can be anything, but must follow with "bert"
SELECT * FROM z_robsTestTable WHERE name like '__bert' 

--Selects all city starting with "b", "s", or "p"
SELECT * FROM z_robsTestTable WHERE city like '[bsp]%'

WHERE and/or Logic

--and
SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin'

--or
SELECT * FROM Customers WHERE City='Berlin' OR City='München';

--Combining AND & OR
SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München');

--in - select multiple records at once
SELECT * FROM z_robsTestTable WHERE primaryid IN (1,2,34,32)