SQL WHERE Clause

0
62

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
SHARE
Previous articleSQL INSERT INTO Statement
Next articleSQL LIKE Clause

Hello Itsourcecoders, welcome to itsourcecode.com. I’m Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I’ve learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!

LEAVE A REPLY

Please enter your comment!
Please enter your name here