fastread homefastrread library fastread menu

MariaDB : IN Condition

Tutorial by:      Date: 2016-04-18 05:05:02

❰ Previous Next ❱

This MariaDB tutorial explains how to use the MariaDB IN condition with syntax and examples.

Description

The MariaDB IN condition is used to help reduce the need to use multiple OR conditions in a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax

The syntax for the IN condition in MariaDB is:

expression IN (value1, value2, .... value_n);

Parameters or Arguments

expression

A value to test.

value1, value2 ..., or value_n

The values to test against expression.

Note

  • The MariaDB IN condition will return the records where expression is value1, value2..., or value_n.
  • The MariaDB IN condition is also called the MariaDB IN operator.

Example - With Character

Let's look at an example of how to use the IN condition with character values in MariaDB.

For example:

SELECT *

FROM sites

WHERE site_name IN ('Fastread.aitechtonic.com', 'CheckYourMath.com', 'BigActivities.com');

This MariaDB IN condition example would return all rows from the sites table where the site_name is either 'Fastread.aitechtonic.com' or 'CheckYourMath.com. Because the * is used in the SELECT, all fields from the sites table would appear in the result set.

The above IN example is equivalent to the following SELECT statement:

SELECT *

FROM sites

WHERE site_name = 'Fastread.aitechtonic.com'

OR site_name = 'CheckYourMath.com'

OR site_name = 'BigActivities.com';

As you can see, using the MariaDB IN condition makes the statement easier to read and more efficient.

Example - With Numeric

Next, let's look at an example of how to use the IN condition with numeric values in MariaDB.

For example:

SELECT *

FROM sites

WHERE site_id IN (1, 2, 3, 99);

This MariaDB IN condition example would return all sites where the site_id is either 1, 2, 3, or 99.

The above IN example is equivalent to the following SELECT statement:

SELECT *

FROM sites

WHERE site_id = 1

OR site_id = 2

OR site_id = 3

OR site_id = 99;

Example - Using NOT operator

Finally, let's look at an example of how to use the IN condition with the NOT operator in MariaDB.

For example:

SELECT *

FROM sites

WHERE site_name NOT IN ('Fastread.aitechtonic.com', 'CheckYourMath.com');

This MariaDB IN condition example would return all rows from the sites table where the site_name is not 'Fastread.aitechtonic.com' or 'CheckYourMath.com'. Sometimes, it is more efficient to list the values that you do not want, as opposed to the values that you do want.

 

❰ Previous Next ❱


MariaDB

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website