|
Logical Operators
A logical
operator
is part of a
Query,
i.e. an enquiry on a database. Logical operators are used to compare logical expressions. For example, to check if two expressions are equal or not.
An exception to this are
NULL
values. With NULL-values the result of logical operations can be unknown.
Logical Operators and examples
-
= (equal)
select * from your_table
where a = b
-
<> (not equal)
select * from your_table
where a <> b
-
!= (not equal)
select * from your_table
where a != b
-
> (greater than)
select * from your_table
where a > b
-
>= (greater or equal)
select * from your_table
where a >= b
-
< (less than)
select * from your_table
where a < b
-
=< (less or equal)
select * from your_table
where a =< b
-
!> (not greater than)
select * from your_table
where a !> b
-
!< (not less than)
select * from your_table
where a !< b
-
and (combines logical expressions)
if (@a > @b) and (@a != @d)
-
or (combines logical expressions)
if (@a > @b) or (@a != @d)
-
not (negates logical expressions)
-
[not] like
(see
pattern matching operators)
-
[not] in
select * from your_table
where a in (1, 5, 8)
The same result can be achieved using the query:
select * from your_table
where a = 1 or a = 5 or a = 8
-
[not] between
select * from your_table
where id between 100 and 150
-
*=
outer join
operator
-
=*
outer join
operator
-
exists
subquery
operator
-
any
subquery
operator
-
all
subquery
operator
-
in
subquery
operator
See also:
string operators,
numeric operators,
pattern match operators
and
Bit Operators.
|