SQL PHP HTML ASP JavaScript articles and free scripts to download
SQL

SQL WHERE Command

WHERE clause 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 desire 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 same table to work with where clause.
Here is the table
id name class mark
1 John Deo Four 75
2 Max Ruin Three 85
3 Arnold Three 55
4 Krish Star Four 60
5 John Mike Four 60
6 Alex John Four 55
Here is the command.

SELECT * from student where class='Four'

Here is the result
id name class mark
1 John Deo Four 75
4 Krish Star Four 60
5 John Mike Four 60
6 Alex John Four 55
This will return all the records from the table name=student of class=Four. This is what we require to get all the records of fourth standard students. Now let us add little more requirement to this and go for all the records of students of fourth standard who have scored mark more than 70.

SELECT * FROM student where class = 'Four' and mark >70

id name class mark
1 John Deo Four 75
We have added one more condition in where clause with a AND combination. This query will return all student records of Fourth class who have scored more than 70. There are different logical combinations can work on different type of fields depending on the condition we have selected. We can see all the non numeric fields we have to use quotes and for numeric fields we need to use quotes. Now let us try some more commands and see what result we will get.

SELECT * FROM `student` WHERE mark between 50 and 70

id name class mark
3 Arnold Three 55
4 Krish Star Four 60
5 John Mike Four 60
6 Alex John Four 55
This will return all the records of the student table that have scored marks between 50 and 70. Between clause is important when we are searching for a rang of records.

Using LIKE with WHERE

SELECT * FROM `student` WHERE name LIKE '%John%'

id name class mark
1 John Deo Four 75
5 John Mike Four 60
6 Alex John Four 55
This search will return us all the records for which inside the name field 'John' is used. John name can be a part of the field. This will return records having name = John Deo or John Mike and even names like Alex John.

Read more on SQL LIKE tutorial here

Google+

Raju11-04-2013
Can we use Where condition linking more that one table?
wale23-02-2014
I have 12 tables with the same number of fields and field names. I want to sum one of those fields that have numerical values in all tables. How can I accomplish the task.
Ivan13-09-2014
Anyone can help me how to resolve this issue?? I am getting a type mismatch with the below syntax... I dont know how to resolve it..

adoCompName.RecordSource = "SELECT * FROM Tbl_Comp_Dtl WHERE CompName = ' * " & Text1.Text & " '"
adoCompName.Refresh
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer