From fb310f17812e7321599845a29af2f36c7f1191c3 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 8 Apr 2021 10:51:26 +0200 Subject: doc: Prefer explicit JOIN syntax over old implicit syntax in tutorial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update src/tutorial/basics.source to match. Author: Jürgen Purtz Reviewed-by: Thomas Munro Reviewed-by: "David G. Johnston" Discussion: https://www.postgresql.org/message-id/flat/158996922318.7035.10603922579567326239@wrigleys.postgresql.org --- src/tutorial/basics.source | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/tutorial/basics.source') 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; ----------------------------- -- cgit v1.2.3