PostgreSQL

Скачать в pdf «PostgreSQL»

| Ocean City


| NJ


|


25


Sandy


| Weber


| Boston


| MA


|


33


Victor


| Tabor


| Williamsport


| PA


|


22


(6 rows)

test=> SELECT * FROM friend


test-> WHERE firstname = ‘Sandy’ AND lastname = ‘Gleason’;


firstname |    lastname    |    city    | state | age


——————+———————-+——————+——-+——


Sandy    | Gleason    | Ocean City | NJ | 25


(1 row)


Figure 4.11: where test for Sandy Gleason


test=> SELECT * FROM friend


test-> WHERE state = ‘NJ’ OR state = ‘PA’


test-> ORDER BY firstname;


firstname


| lastname


| city


| state


| age


Dick


| Gleason


| Ocean City


| NJ


| 19


Sandy


| Gleason


| Ocean City


| NJ


| 25


Victor


| Tabor


| Williamsport


| PA


| 22


(3 rows)

Figure 4.12: Friends in New Jersey and Pennsylvania


in the where clause. If we tested for firstname = ‘Sandy’, we would select both Sandy Gleason and Sandy Weber. If we tested for lastname = ‘Gleason’, we would get both Sandy Gleason and her brother Dick Gleason. The proper approach is to use and to test both firstname and lastname. This query is shown in Figure
4.11. The and combines the two needed comparisons.

Скачать в pdf «PostgreSQL»