Relational operators in SQL
Operators are symbols that allow you to perform mathematical operations, concatenate strings, make comparisons.
Types of Relational Operators - Oracle SQL
- Relational (or comparison)
- Arithmetic
- Concatenation
- Logical
For now we will only see the first ones.
Comparison in SQL
Relational (or comparison) operators allow us to compare two expressions, which can be variables, field values, etc.
We have learned to specify equal conditions to select records from a table; for example:
select * from books
where author = 'Borges';
We use the relational equality operator.
Relational operators bind a field to a value so that Oracle compares each record (the specified field) to the given value.
The relational operators are as follows:
= equal
<> different
> major
<minor
> = greater than or equal
<= less than or equal
We can select the records whose author is different from "Borges", for this we use the condition:
select * from books
where author <> 'Borges';
We can compare numerical values. For example, we want to show the titles and prices of books whose price is greater than 20 pesos:
select title, price
from books
where price> 20;
We want to select the books whose price is less than or equal to 30:
select * from books
where price <= 30;
Relational operators compare values of the same type. They are used to check if a field meets a condition.
They are not the only ones, there are others that we will see later.
Comments
Post a Comment