SQL - WHERE Clause - 1keydata
SQL - WHERE Clause - 1keydata
SQL Tutorial
Basic SQL Commands
SQL SELECT
SQL DISTINCT
SQL WHERE SQL > SQL Commands > WHERE Clause
SQL AND OR
We can use the WHERE clause to filter the result set based on certain conditions. The syntax for using WHERE in the
SQL IN
follows:
SQL BETWEEN
SQL Wildcard
SELECT "column_name"
SQL LIKE FROM "table_name"
SQL ORDER BY WHERE "condition";
SQL GROUP BY
SQL HAVING "Condition" can include a single comparison clause (called simple condition) or multiple comparison clauses combined tog
SQL ALIAS OR operators (compound condition).
SQL AS
SQL SELECT UNIQUE Example 1: WHERE Clause With Simple Condition
SQL JOIN
SQL INNER JOIN To select all stores with sales above $1,000 in Table Store_Information,
SQL OUTER JOIN
Table Store_Information
SQL LEFT OUTER JOIN
SQL CROSS JOIN Store_Name Sales Txn_Date
SQL INSERT INTO
Los Angeles 1500 Jan-05-1999
SQL INSERT INTO SELECT
San Diego 250 Jan-07-1999
SQL UPDATE
Los Angeles 300 Jan-08-1999
SQL DELETE FROM
Boston 700 Jan-08-1999
Advanced SQL
SQL UNION we key in,
SQL UNION ALL
SQL Inline View SELECT Store_Name
SQL INTERSECT FROM Store_Information
SQL MINUS WHERE Sales > 1000;
SQL LIMIT
SQL TOP Result:
SQL Subquery
SQL EXISTS Store_Name
SQL CASE Los Angeles
SQL DECODE
SQL AUTO INCREMENT Example 2: WHERE Clause With OR Operator
SQL IDENTITY
SEQUENCE & NEXTVAL To view all data with sales greater than $1,000 or with transaction date of 'Jan-08-1999', we use the following SQL,
SQL Functions
SELECT *
SQL Average
FROM Store_Information
SQL COUNT WHERE Sales > 1000 OR Txn_Date = 'Jan-08-1999';
SQL MAX
SQL MIN Result:
SQL SUM
SQL ROUND
Store_Name Sales Txn_Date
String Functions Los Angeles 1500 Jan-05-1999
SQL CAST Los Angeles 300 Jan-08-1999
SQL CONVERT Boston 700 Jan-08-1999
SQL CONCATENATE
SQL SUBSTRING
Using WHERE With UPDATE and DELETE
SQL INSTR
SQL TRIM In addition to the SELECT statement, the WHERE clause can also be used with UPDATE and DELETE statements. Examples
http://www.1keydata.com/sql/sqlwhere.html 1/2
3/2/2016 SQL WHERE Clause | 1Keydata
In addition to the SELECT statement, the WHERE clause can also be used with UPDATE and DELETE statements. Examples
SQL LENGTH WHERE clause with these two commands can be seen in the UPDATE and DELETE sections.
SQL REPLACE
SQL TO_DATE
Date Functions
Exercises
For these exercises, assume we have a table called Users with the following data:
Table Users
1. Which of the following SQL statement is valid? (There can be more than one answer)
a) SELECT * FROM Users WHERE Gender = 'M';
b) SELECT * WHERE Gender = 'M' FROM Users;
c) SELECT Gender= 'M' FROM Users;
d) SELECT Gender FROM Users WHERE Last_Name = 'Wilkes';
3. (True or False) The condition used in the WHERE clause must include a column that is part of the SELECT clause.
Show Answers
Copyright © 2016 1keydata.com All Rights Reserved Privacy Policy About Contact
http://www.1keydata.com/sql/sqlwhere.html 2/2