Pages

Wednesday, January 19, 2011

WHERE

WHERE

--==============================================[ WHERE ]=====================================================================
--The SQL WHERE clause is used to select data conditionally, by adding it to already existing SQL SELECT query.

--Where (equal to)---
SELECT * FROM Person.Contact
WHERE LastName='Achong'

--Where (Not equal <>)--
SELECT * FROM Person.Contact
WHERE LastName <> 'Achong'

--Where (Greater than >)---
SELECT * FROM Person.Contact
WHERE ContactID > 5

--Where (Greater or equal >= )---
SELECT * FROM Person.Contact
WHERE ContactID >= 5

--Where (Less than <)---
SELECT * FROM Person.Contact
WHERE ContactID < 5

--Where (Less or equal <=)
SELECT * FROM Person.Contact
WHERE ContactID <= 5

--Where Like ----
SELECT * FROM Person.Contact
WHERE LastName Like 'Ach%'

SELECT * FROM Person.Contact
WHERE Phone Like '398%'

            -- Wildcard Concept: first digit of the number is between 3-6, second digit can be any number _, third digit should be 4 and rest cab be any number
SELECT * FROM Person.Contact
WHERE Phone LIKE '[3-6]_4%'


--Where Between--
SELECT * FROM Person.Contact
WHERE ContactID BETWEEN '1' AND '50'

--Where In-----
SELECT * FROM Person.Contact
WHERE ContactID IN ('1', '15')

No comments:

Post a Comment