PostgreSQL

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


Continuing with our friend table, suppose Mike had a birthday, so we want to update his age in the table. The example in Figure 3.13 shows the word UPDATE, the table name friend, followed by SET, then the column name, the equals sign (=), and the new value. The where clause controls which rows are affected by the update, just as in a delete operation. Without a where clause, all rows are updated.


Notice that the Mike row has moved to the end of the list. The next section will explain how to control the order of the display.

3.8    Sorting Data with Order By


In a select query, rows are displayed in an undetermined order. To guarantee that the rows will be returned from select in a specific order, you must add the order by clause to the end of the select. Figure
3.14 shows the use of order by. You can reverse the order by adding DESC, as shown in Figure 3.15. If the query also used a WHERE clause, the ORDER BY would appear after the WHERE clause, as in Figure 3.16.


You can ORDER BY more than one column by specifying multiple column names or labels, separated by commas. The command would then sort by the first column specified. For rows with equal values in the first column, it would sort based on the second column specified. Of course, this approach is not useful in the friend example because all column values are unique.

3.9    Destroying Tables


This chapter would not be complete without showing you how to remove tables. This task is accomplished using the DROP TABLE command. For example, the command DROP TABLE friend will

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