Java Reference
In-Depth Information
F
IGURE
32.12
The result of the
select
statement is displayed in the MySQL console.
32.3.6 Comparison and Boolean Operators
SQL has six comparison operators, as shown in TableĀ 32.1, and three Boolean operators, as
shown in TableĀ 32.2.
T
ABLE
32.1
T
ABLE
32.2
Comparison Operators
Boolean Operators
Operator
Description
Operator
Description
=
Equal to
not
Logical negation
<>
or
!=
Not equal to
and
Logical conjunction
<
Less than
or
Logical disjunction
Less than or equal to
<=
>
Greater than
>=
Greater than or equal to
Note
The comparison and Boolean operators in SQL have the same meanings as in Java. In
SQL the
equal to
operator is
=
, but in Java it is
==
. In SQL the
not equal to
operator is
<>
or
!=
, but in Java it is
!=
. The
not
,
and
, and
or
operators are
!
,
&&
(
&
), and
||
(
|
) in Java.
Query 2:
Get the names of the students who are in the CS dept and live in the ZIP code
31411.
select
firstName, mi, lastName
from
Student
where
deptId =
'CS'
and zipCode =
'31411'
;
Note
To select all the attributes from a table, you don't have to list all the attribute names
in the select clause. Instead, you can just use an
asterisk
(*), which stands for all the
attributes. For example, the following query displays all the attributes of the students
who are in the CS dept and live in ZIP code 31411.
select
*
from
Student
where
deptId =
'CS'
and zipCode =
'31411'
;
Search WWH ::
Custom Search