MariaDB uses SQL (Structured Query Language) and it is an open-source relational database management system (RDBMS) for managing and manipulating data. The WHERE clause in SQL queries is used to filter and obtain specific data. The ability to remove and retrieve specific data using the WHERE clause in SQL queries is one of the main features that makes MariaDB robust. This article will examine the syntax and many uses for the WHERE clause in MariaDB.
MariaDB's WHERE Clause
The WHERE clause, which defines a search criterion for picking rows, is an optional component in the select statement. To filter the results of a SELECT, INSERT, UPDATE, or DELETE query, we will use the WHERE clause in MariaDB.
Syntax:
SELECT column1, column2, ... FROM table_name WHERE condition;
- SELECT Clause: It specifies the columns you want to retrieve from the table.
- FROM Clause: It specifies the table from which the data will be retrieved.
- WHERE condition: It filters the rows based on specific conditions and it is the statement that details the standards by which the data will be filtered.
Common Operators Used With WHERE Clause
- =
- <> or !=
- <
- >
- <=
- >=
- AND, OR, NOT
Let's create a table employees and insert data into this.
Query:
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
department_id INT,
salary DECIMAL(10, 2)
);
Query:
INSERT INTO employees VALUES
(1, 'John', 'Doe', 3, 50000.00),
(2, 'Jane', 'Smith', 2, 60000.00),
(3, 'Bob', 'Johnson', 1, 75000.00),
(4, 'Alice', 'Williams', 2, 65000.00),
(5, 'Charlie', 'Brown', 1, 70000.00);
WHERE Clause With Single Condition
Query:
SELECT * FROM employees WHERE salary > 30000;
This query will retrieve all the rows in the employees table where salary is greater than 30000.
Output:
WHERE Clause
WHERE Clause With Comparison Operators
Query:
SELECT * FROM employees WHERE first_name = 'John';
This query will retrieve employess with first name john
Output:
WHERE Clause
Query:
SELECT * FROM employees WHERE salary <> 60000;
This query will retrieve employees with salary not equal to 6000
Output:
WHERE Clause
WHERE Clause With Logical Operators
Query:
SELECT * FROM employees WHERE salary > 50000 AND department_id = 1;
This query will give all the employees who have salary greater than 5000 and belongs to it department,
Output:
WHERE Clause
Query:
SELECT * FROM employees WHERE salary < 50000 OR department_id = 2;
This query will give all the employees who have salary less than 5000 or who belongs to sales department.
Output:
WHERE Clause
Query:
SELECT * FROM employees WHERE NOT department_id = 1;
This query will give all the employees who does not belongs to it department.
Output:
WHERE Clause
Conclusion
In MariaDB, the WHERE clause is an effective tool for selecting and obtaining certain data from tables. It is essential to comprehend its syntax and different operators when creating accurate and efficient SQL queries. Understanding the WHERE clause is crucial for effective database management in MariaDB, whether you are retrieving information, editing entries, or removing records.
Similar Reads
MariaDB Having Clause
The HAVING clause is crucial for filtering and aggregating data in database queries. The MariaDB HAVING clause syntax is outlined. It breaks down into components. These include the SELECT clause, aggregate functions, and the GROUP BY clause. The SELECT clause specifies columns. Aggregate functions p
6 min read
Create Table in MariaDB
MariaDB is an open-source RDBMS that has become famous for its speed, and scalability. MariaDB Stores data in tables with structured relationships between them. In terms of working with databases, one crucial element involves the construction of tables for organizing and storing data effectively. In
4 min read
Alter Table in MariaDB
MariaDB is an open-source RDBMS, that offers an extensive collection of features for handling database structures effectively. One important part of database management is changing tables to meet needs or improve performance. The ALTER TABLE command in MariaDB assists in these changes, allowing user
5 min read
SQLite WHERE Clause
SQLite is the serverless database engine that is used most widely. It is written in c programming language and it belongs to the embedded database family. In this article, you will be learning about the where clause and functionality of the where clause in SQLite. Where ClauseSQLite WHERE Clause is
3 min read
SQL | WHERE Clause
The SQL WHERE clause allows to filtering of records in queries. Whether you're retrieving data, updating records, or deleting entries from a database, the WHERE clause plays an important role in defining which rows will be affected by the query. Without it, SQL queries would return all rows in a tab
4 min read
Declaring Variable in MariaDB
Variables serve as essential components in database management systems like MariaDB facilitating the storage and manipulation of data within the database environment. Variable declaration in MariaDB is a fundamental concept, allowing users to store values temporarily, perform calculations, and strea
4 min read
MariaDB GROUP BY Clause
An important feature in MariaDB, and SQL in general, is the GROUP BY clause. This article explains the important features of the GROUP BY clause in MariaDB. This article explains you the syntax of the GROUP BY clause and its practical applications. Examples include using the aggregate functions, gro
6 min read
Comparison Operator in MariaDB
In the world of database management, precise comparisons are essential for accurate data retrieval and manipulation. MariaDB, a powerful open-source relational database system, offers a range of comparison operators to help us filter and query our data effectively. In this article, We will learn abo
5 min read
Parameterize an MySQL IN Clause
In MySQL, the IN clause is a powerful tool for filtering data based on a specified list of values. To enhance flexibility and security, parameterizing the IN clause is a recommended practice. In this article, we will understand the Parameterize a MySQL IN clause with the practice of parameterizing a
5 min read
SET Variable in MariaDB
In MariaDB, the SET statement is a main tool in variable handling. Users can assign values to variables, operate with them, and control database operations in various respects. This article includes a look at the SET variable usage in MariaDB and its syntax together with some examples. SET Variable
4 min read