Skip to content

Instantly share code, notes, and snippets.

@melnikovdv
Created August 15, 2022 14:56
Show Gist options
  • Save melnikovdv/7b1cf08bea4f0bcc708f3a7b1a1bfb89 to your computer and use it in GitHub Desktop.
Save melnikovdv/7b1cf08bea4f0bcc708f3a7b1a1bfb89 to your computer and use it in GitHub Desktop.
SQL question
CREATE TABLE track(
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL
);
CREATE TABLE playlist(
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL
);
-- Many-to-many relationship:
-- One track can be included in several playlists
-- One playlists contains several tracks
CREATE TABLE track_to_playlist(
id SERIAL PRIMARY KEY,
trace_id INTEGER NOT NULL UNIQUE REFERENCES track(id),
playlist_id INTEGER NOT NULL UNIQUE REFERENCES playlist(id)
);
-- Task: write an SQL query to retrieve all tracks
-- which are not included into any playlist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment