ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

SQL WHERE Clause

sqltuts

SQL WHERE clause is an optional clause used to define what records are to be included in the query. We use conditional operators like <, >, =, >=, <=, !=(<>) , BETWEEN a AND b, IN(list) etc.

 

Syntax:

 

  1. SELECT <field>,<field>
  2. FROM <table_name>
  3. WHERE <field> <operator> <value>;

 

For example we have a table Employee:

 

Employee_id First_name Last_name sex
123 Mack Johnson male
124 Jack Obama male
125 Queen Khan female

 

Now, if we want to select the first name and employee_id of only the ones who are males:

 

  1. SELECT Employee_id, First_name
  2. FROM Employee
  3. WHERE sex = ‘male’;

 

This will give the following result:

 

Employee_id First_name
123 Mack
124 Jack

 

For strings , we always enclose them in single quotes.

 

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!