SQL WHERE CommandWHERE 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
Here is the command.
SELECT * from student where class='Four'Here is the result
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
SELECT * FROM `student` WHERE mark between 50 and 70
Using LIKE with WHERE
SELECT * FROM `student` WHERE name LIKE '%John%'
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
Could not connect to MySQL