Category: Operators and Clauses
-
Not Operator
Most of the times, there is a need to use two or more conditions to filter required records from a table; but sometimes satisfying one of the conditions would be enough. There are also scenarios when you need to retrieve records that do not satisfy the conditions specified. SQL provides logical connectives for this purpose. They are…
-
Case
The SQL CASE Statement The SQL CASE statement is a conditional statement that helps us to make decisions based on a set of conditions. It evaluates the set of conditions and returns the respective values when a condition is satisfied. The CASE statement works like a simplified IF-THEN-ELSE statement and allows for multiple conditions to be tested.…
-
Exists Operator
The SQL EXISTS Operator The SQL EXISTS operator is used to verify whether a particular record exists in a MySQL table. While using this operator we need to specify the record (for which you have to check the existence) using a subquery. The EXISTS operator is used in the WHERE clause of a SELECT statement to filter records based on the…
-
Any, All Operators
The SQL ANY and ALL operators are used to perform a comparison between a single value and a range of values returned by the subquery. The ANY and ALL operators must be preceded by a standard comparison operator i.e. >, >=, <, <=, =, <>, != and followed by a subquery. The main difference between ANY and…
-
In Operator
The SQL IN Operator The SQL IN Operator is used to specify multiple values or sub query in the WHERE clause. It returns all rows in which the specified column matches one of the values in the list. The list of values or sub query must be specified in the parenthesis e.g. IN (select query) or IN (Value1, Value2, Value3, …). In…
-
Like Operator
The SQL LIKE Operator The SQL LIKE operator is used to retrieve the data in a column of a table, based on a specified pattern. It is used along with the WHERE clause of the UPDATE, DELETE and SELECT statements, to filter the rows based on the given pattern. These patterns are specified using Wildcards. Suppose we need…
-
Boolean
A Boolean is a universal data type which stores true or false values. It is used when we define a variable in a column of the table. For instance, a customer wants a list of all the red cars. So, we can find this using the BOOLEAN operator as given in the below table − Here, IS_RED is the BOOLEAN column…
-
AND and OR Operators
Operators are reserved words primarily used in SQL to perform various operations on data, like addition (+), subtraction (-), or comparison (==). Conjunctive operators, specifically used in boolean logic, combines two conditions in an SQL statement. The most common conjunctive operators are: AND (&&), which returns true if both conditions are true, and OR (||),…
-
Having Clause
The SQL HAVING Clause The SQL HAVING clause is similar to the WHERE clause; both are used to filter rows in a table based on specified criteria. However, the HAVING clause is used to filter grouped rows instead of single rows. These rows are grouped together by the GROUP BY clause, so, the HAVING clause must always…
-
Group By Clause
The SQL GROUP BY Clause The SQL GROUP BY clause is used in conjunction with the SELECT statement to arrange identical data into groups. This clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY and HAVING clauses (if they exist). The main purpose of grouping the records of a table based on…