MasteringDatabases
Search
Table of Contents
Book Index
User
Course Home
Assignments
Practice
Peer Instruction (Instructor)
Peer Instruction (Student)
Change Course
Instructor's Page
Progress Page
Edit Profile
Change Password
Register
Login
Dark Mode
Scratch Activecode
Help
FAQ
Instructors Guide
About Runestone
Report A Problem
This Chapter
Test of Outer Join
14.1 Outer Join by Examples
14.2 A Generic Version of OuterJoin
Test of Outer Join
ΒΆ
SELECT S.Name AS Street, U.* FROM Streets S LEFT OUTER JOIN Users U ON U.Streetid = S.Id;
DROP TABLE IF EXISTS OuterJoinStreetUser; CREATE TABLE OuterJoinStreetUser AS SELECT S.Name AS Street, U.* FROM Streets S LEFT OUTER JOIN Users U ON U.Streetid = S.Id; SELECT Street, Count(Username) AS COUNT FROM OuterJoinStreetUser GROUP BY Street;
DROP TABLE IF EXISTS Streets; CREATE TABLE Streets ( ID INT PRIMARY KEY, Name VARCHAR(100) ); DROP TABLE IF EXISTS users; CREATE TABLE users ( Username VARCHAR(100) PRIMARY KEY, StreetID INT REFERENCES Streets ( ID ) ); INSERT INTO Streets VALUES ( 1, '1st street' ), ( 2, '2nd street' ), ( 3, '3rd street' ), ( 4, '4th street' ), ( 5, '5th street' ); INSERT INTO users VALUES ( 'Pol', 1 ), ( 'Doortje', 1 ), ( 'Marc', 2 ), ( 'Bieke', 2 ), ( 'Paulien', 2 ), ( 'Fernand', 2 ), ( 'Pascal', 2 ), ( 'Boma', 3 ), ( 'Goedele', 3 ), ( 'Xavier', 4 );
You have attempted
of
activities on this page