TechMynd, Fresh Downloads and Latest Technology News, Stuff That Works | Downloads, Tips & Tricks, Softwares, Programming, Resources, IT, Computer, Resources, Freewares

SQL WHERE Command



WHERE command is used to collect the records from the table based on some condition specified by the where clause. More than one condition can be added to the where clause by using various logical expressions like AND, OR, < ( less than ), >(greater than) etc. Logical expressions plays important role in returning the desired records. Let us start with some examples. We are interested in the marks of Fourth class students. You can just follow the table creation process and the select query section discussed here. We will use the table named as student to work with WHERE clause.
Here is the table.

id name class marks
1 javed four 76
2 aamir three 34
3 aijaz two 77
4 sohail four 33

SELECT * from student where class=’Four’
Here is the result.

id name class marks
1 javed four 76
4 sohail four 33

This will return all the records from the table of class Four. This is what we require to get all the records of fourth standard students.

Other possible WHERE queries can be like these:

SELECT * FROM student where class = ‘Four’ and mark >77
SELECT * FROM `student` WHERE mark between 33 and 76
SELECT * FROM `student` WHERE name like ‘%sohail%’

Like is special treatment. It can be used as following.
SELECT * FROM `student` WHERE name like ‘%sohail’
SELECT * FROM `student` WHERE name like ’sohail%’
SELECT * FROM `student` WHERE name like ‘%sohail%’

%sohail will also fetch record like Najam Sohail
sohail% will also fetch record like Sohail Nadeem
%sohail% will also fetch record like abcd Sohail xyz

While = will see for exact matching value.

Tags:
Posted in: mySQL
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Related Posts


One Response to “SQL WHERE Command”

  1. Oct 6, 2007
    John Says: Reply to this comment

    Detailed SQL WHERE Command post. Thank you.

Post a Comment

Comment will appear here after approval, Thanks for patience

  Subscribe Via RSS
  Subscribe Via Email

Add to Technorati Favorites

Donate towards TechMynd web hosting Bill!