How to use WHERE Clause in MySQL

MySQL – WHERE Clause in MySQL

The Where clause is used to specify the condition while fetching the specific records from MySQL Database. In other words, The Where clause is used to fetch only those records that fulfill a specified condition. If the condition is satisfied then only records will be displayed.

WHERE Clause in MySQL

Syntex

The WHERE clause is not only used in SELECT Query but also used in INSERT, UPDATE, and DELETE Query.

The WHERE clause plays an important role for a large amount data.

WHERE Clause in MySQL

Expand Requery Edit Explain Profiling Bookmark Database Database: tutorialdemo 

Comparison or Logical operators in the WHERE Clause in MySQL

OperatorDescriptionExample
=Equal, check with the two operands are equal or not(A=B)
>Greater than(A>B)
<Less than(A<B)
<=Less than or equal(A<=B)
>=Greater than or equal(A>=B)
<> or !=Not equal(A<>B)(A!=B)
BETWEENBetween is used for certain date rangeBetween ’01-Dec-2020′ and ’12-Dec-2020′
LIKELike used for search the specifc kewordLIKE ‘%HTML%’
INRetrive the multiple records IN (‘2′,’3’)

WHERE Clause in MySQL with Logical operators

Example :

The following example query would fetch the id, firstname, lastname, and feeamount fields from members table where feeamount is greater the 3000.

WHERE Clause in MySQL with Logical operators
Example 2:

The following SELECT statement would fetch the specific records from the members table using id.

The PHP code

The following PHP code will display the id, firstname, lastname, address and feeamount from the members table.