fastread homefastrread library fastread menu

MariaDB : WHERE Clause

Tutorial by:      Date: 2016-04-18 05:00:22

❰ Previous Next ❱

This MariaDB tutorial explains how to use the MariaDB WHERE clause with syntax and examples.

Description

The MariaDB WHERE clause is used to filter the results from a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax

The syntax for the WHERE clause in MariaDB is:

WHERE conditions;

Parameters or Arguments

conditions

The conditions that must be met for records to be selected.

Example - With Single condition

Let's look at how to use the WHERE clause to filter results based on one condition in MariaDB.

For example:

SELECT *

FROM sites

WHERE site_name = 'Fastread.aitechtonic.com';

In this WHERE clause example, we've used the WHERE clause to filter our results from the sites table. The SELECT statement above would return all rows from the sites table where the site_name is 'Fastread.aitechtonic.com'. Because the * is used in the SELECT, all columns from the sites table would appear in the result set.

Example - Using AND condition

Let's look at how to use the AND condition within the WHERE clause in MariaDB.

For example:

SELECT *

FROM sites

WHERE site_name = 'Fastread.aitechtonic.com';

AND site_id <= 500;

This MariaDB WHERE example uses the WHERE clause to define multiple conditions. In this example, the SELECT statement uses the AND condition to return all sites that where the site_name is 'Fastread.aitechtonic.com' and the site_id is less than or equal to 500.

Example - Using OR condition

Let's look at how to use the OR condition within the WHERE clause in MariaDB.

For example:

SELECT site_id, site_name

FROM sites

WHERE site_name = 'CheckYourMath.com'

OR site_name = 'Fastread.aitechtonic.com';

This WHERE clause example uses the WHERE clause to define multiple conditions, but instead of using the AND condition, it uses the OR condition. In this case, this SELECT statement would return all site_id and site_name values where the site_name is 'CheckYourMath.com' or 'Fastread.aitechtonic.com'.

Example - Combining AND & OR conditions

Let's look at how to combine the AND condition and the OR condition within the WHERE clause in MariaDB.

For example:

SELECT *

FROM sites

WHERE (site_name = 'CheckYourMath.com' AND site_id < 100)

OR (site_name = 'Fastread.aitechtonic.com');

This WHERE clause example uses the WHERE clause to define multiple conditions, but it combines the AND condition and the OR condition. This example would return all sites that have a site_name of 'CheckYourMath.com' and the site_id is less than 100 as well as all sites that have a site_name of 'Fastread.aitechtonic.com'.

The parentheses determine the order that the AND and OR conditions are evaluated. Just like you learned in the order of operations in Math class!

 

❰ Previous Next ❱


MariaDB

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website