diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2021-04-08 10:51:26 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2021-04-08 10:51:26 +0200 |
commit | fb310f17812e7321599845a29af2f36c7f1191c3 (patch) | |
tree | 895947392d626a222ef8693712aa65b166043013 /src/tutorial | |
parent | 6b4d23feef6e334fb85af077f2857f62ab781848 (diff) | |
download | postgresql-fb310f17812e7321599845a29af2f36c7f1191c3.tar.gz postgresql-fb310f17812e7321599845a29af2f36c7f1191c3.zip |
doc: Prefer explicit JOIN syntax over old implicit syntax in tutorial
Update src/tutorial/basics.source to match.
Author: Jürgen Purtz <juergen@purtz.de>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: "David G. Johnston" <david.g.johnston@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/158996922318.7035.10603922579567326239@wrigleys.postgresql.org
Diffstat (limited to 'src/tutorial')
-rw-r--r-- | src/tutorial/basics.source | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/tutorial/basics.source b/src/tutorial/basics.source index fe1cdfde2a8..3e74d718ab0 100644 --- a/src/tutorial/basics.source +++ b/src/tutorial/basics.source @@ -97,42 +97,38 @@ SELECT DISTINCT city -- The following joins the weather table and the cities table. -SELECT * - FROM weather, cities - WHERE city = name; +SELECT * FROM weather JOIN cities ON city = name; -- This prevents a duplicate city name column: SELECT city, temp_lo, temp_hi, prcp, date, location - FROM weather, cities - WHERE city = name; + FROM weather JOIN cities ON city = name; -- since the column names are all different, we don't have to specify the -- table name. If you want to be clear, you can do the following. They give -- identical results, of course. SELECT weather.city, weather.temp_lo, weather.temp_hi, weather.prcp, weather.date, cities.location - FROM weather, cities - WHERE cities.name = weather.city; + FROM weather JOIN cities ON weather.city = cities.name; --- JOIN syntax +-- Old join syntax SELECT * - FROM weather JOIN cities ON (weather.city = cities.name); + FROM weather, cities + WHERE city = name; -- Outer join SELECT * - FROM weather LEFT OUTER JOIN cities ON (weather.city = cities.name); + FROM weather LEFT OUTER JOIN cities ON weather.city = cities.name; -- Suppose we want to find all the records that are in the temperature range -- of other records. w1 and w2 are aliases for weather. SELECT w1.city, w1.temp_lo, w1.temp_hi, w2.city, w2.temp_lo, w2.temp_hi -FROM weather w1, weather w2 -WHERE w1.temp_lo < w2.temp_lo - and w1.temp_hi > w2.temp_hi; +FROM weather w1 JOIN weather w2 + ON w1.temp_lo < w2.temp_lo AND w1.temp_hi > w2.temp_hi; ----------------------------- |