1- <!-- $PostgreSQL: pgsql/doc/src/sgml/query.sgml,v 1.47 2006/09/16 00:30:15 momjian Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/query.sgml,v 1.48 2006/10/21 23:12:57 tgl Exp $ -->
22
33 <chapter id="tutorial-sql">
44 <title>The <acronym>SQL</acronym> Language</title>
2020 <para>
2121 In the examples that follow, we assume that you have created a
2222 database named <literal>mydb</literal>, as described in the previous
23- chapter, and havestarted <application>psql</application>.
23+ chapter, and havebeen able to start <application>psql</application>.
2424 </para>
2525
2626 <para>
3535</screen>
3636
3737 This creates the scripts and compiles the C files containing user-defined
38- functions and types. (You must use GNU make for this — it may be named
39- something different on your system, often <application>gmake</>.)
38+ functions and types. (If you installed a pre-packaged version of
39+ <productname>PostgreSQL</productname> rather than building from source,
40+ look for a directory named <filename>tutorial</> within the
41+ <productname>PostgreSQL</productname> documentation. The <quote>make</>
42+ part should already have been done for you.)
4043 Then, to start the tutorial, do the following:
4144
4245<screen>
43- <prompt>$</prompt> <userinput>cd <replaceable>....</replaceable>/src/ tutorial</userinput>
46+ <prompt>$</prompt> <userinput>cd <replaceable>....</replaceable>/tutorial</userinput>
4447<prompt>$</prompt> <userinput>psql -s mydb</userinput>
4548<computeroutput>
4649...
@@ -416,7 +419,7 @@ SELECT DISTINCT city
416419 In some database systems, including older versions of
417420 <productname>PostgreSQL</productname>, the implementation of
418421 <literal>DISTINCT</literal> automatically orders the rows and
419- so <literal>ORDER BY</literal> isredundant . But this is not
422+ so <literal>ORDER BY</literal> isunnecessary . But this is not
420423 required by the SQL standard, and current
421424 <productname>PostgreSQL</productname> doesn't guarantee that
422425 <literal>DISTINCT</literal> causes the rows to be ordered.
@@ -518,15 +521,21 @@ SELECT city, temp_lo, temp_hi, prcp, date, location
518521
519522 <para>
520523 Since the columns all had different names, the parser
521- automatically found out which table they belong to, but it is good
522- style to fully qualify column names in join queries:
524+ automatically found out which table they belong to. If there
525+ were duplicate column names in the two tables you'd need to
526+ <firstterm>qualify</> the column names to show which one you
527+ meant, as in:
523528
524529<programlisting>
525530SELECT weather.city, weather.temp_lo, weather.temp_hi,
526531 weather.prcp, weather.date, cities.location
527532 FROM weather, cities
528533 WHERE cities.name = weather.city;
529534</programlisting>
535+
536+ It is widely considered good style to qualify all column names
537+ in a join query, so that the query won't fail if a duplicate
538+ column name is later added to one of the tables.
530539 </para>
531540
532541 <para>
@@ -548,7 +557,7 @@ SELECT *
548557 Now we will figure out how we can get the Hayward records back in.
549558 What we want the query to do is to scan the
550559 <classname>weather</classname> table and for each row to find the
551- matching <classname>cities</classname> row. If no matching row is
560+ matching <classname>cities</classname> row(s) . If no matching row is
552561 found we want some <quote>empty values</quote> to be substituted
553562 for the <classname>cities</classname> table's columns. This kind
554563 of query is called an <firstterm>outer join</firstterm>. (The
@@ -681,11 +690,11 @@ SELECT city FROM weather WHERE temp_lo = max(temp_lo); <lineannotation>WRONG
681690 but this will not work since the aggregate
682691 <function>max</function> cannot be used in the
683692 <literal>WHERE</literal> clause. (This restriction exists because
684- the <literal>WHERE</literal> clause determinesthe rowsthat will
685- go into theaggregation stage ; so it has to be evaluated before
686- aggregate functions are computed.)
693+ the <literal>WHERE</literal> clause determineswhich rows will be
694+ included in theaggregate calculation ; soobviously it has to be evaluated
695+ before aggregate functions are computed.)
687696 However, as is often the case
688- the query can be restated to accomplish theintended result, here
697+ the query can be restated to accomplish thedesired result, here
689698 by using a <firstterm>subquery</firstterm>:
690699
691700<programlisting>
@@ -808,7 +817,7 @@ SELECT city, max(temp_lo)
808817 You can update existing rows using the
809818 <command>UPDATE</command> command.
810819 Suppose you discover the temperature readings are
811- all off by 2 degreesas of November 28. You mayupdate the
820+ all off by 2 degreesafter November 28. You maycorrect the
812821 data as follows:
813822
814823<programlisting>