MariaDB WHERE Clause

In MariaDB, WHERE clause is used with SELECT, INSERT, UPDATE and DELETE statement to select or change a specific location where we want to change.

It is appeared after the table name in a statement.

Syntax:


[COMMAND] field,field2,... FROM table_name,table_name2,... WHERE [CONDITION] 

# Note: WHERE clause is an optional clause. It can be used with AND, OR, AND & OR, LIKE operators.


# WHERE Clause with Single Condition

Example:

We have a table "Students", having some data. Let's retrieve all records from "Student" table where student_id is less than 6.


SELECT * 
FROM Students
WHERE student_id < 6; 

Output:

Mariadb Where clause 1

# WHERE Clause with AND Condition


SELECT *
FROM Students
WHERE student_name = 'Ajeet'
AND student_id >=1 ; 

It would return all columns from "Student" table where "student_name" is Ajeet AND "student_id" is greater than or equal to 1.

Both conditions must be satisfied.

Output:

Mariadb Where clause 2

# WHERE Clause with OR Condition


SELECT *
FROM Students
WHERE student_name = 'Ajeet'
OR student_id >=1 ; 

It would return all columns from "Student" table where "student_name" is Ajeet OR "student_id" is greater than or equal to 1.

Anyone of the condition must be satisfied.

Output:

Mariadb Where clause 3

# WHERE Clause with AND & OR Condition


SELECT *
FROM Students
WHERE student_name = 'Ajeet' 
AND student_id >=1
OR (student_address = 'Delhi'); 

It would return all columns from "Student" table where "student_name" is Ajeet AND "student_id" is greater than or equal to 1 OR student_address is Delhi.

Output:

Mariadb Where clause 4