Normalt får I kun brug for:
Hent personer med adresser:
SELECT
a.navn, b.vejnavn, b.husnr
FROM
person a JOIN
adresse b ON (a.adresseid = b.id)
Hent personer (også dem uden adresser):
SELECT
a.navn, b.vejnavn, b.husnr
FROM
person a LEFT JOIN
adresse b ON (a.adresseid = b.id)
Selects uden FROM kan med fordel benyttes til at oversætte kodeværdier til tekster (hvis man mangler kodelisten)
SELECT
COALESCE(pris.tekst, '<p_ordning ikke angivet!!!>'),
trafik.p_pladser.*
FROM
trafik.p_pladser LEFT JOIN
(
SELECT 'Handicap parkering'::text AS p_ordning, 'Gratis'::text AS tekst UNION
SELECT 'El-Bil plads', 'Gratis' UNION
SELECT 'Grøn betalingszone', 'Billig' UNION
SELECT 'Blå betalingszone', 'Mellempris' UNION
SELECT 'Motorcykel parkering', 'Ukendt' UNION
SELECT 'Taxiholdeplads', 'Gratis' UNION
SELECT '2-timers restriktion', 'Gratis' UNION
SELECT 'Turistbus plads', 'Gratis' UNION
SELECT 'Rød betalingszone', 'Dyr' UNION
SELECT 'Ambassade parkering', 'Gratis' UNION
SELECT 'Besøgsplads', 'Gratis' UNION
SELECT 'Delebil parkering', 'Gratis' UNION
SELECT 'Privat ordning', 'Gratis'
) pris
ON (pris.p_ordning = trafik.p_pladser.p_ordning)
Bemærk:
Øvelse
Prøv at skrive JOINS på nogle af jeres egne data: