Install the SQLite Browser if you haven't already here
Open the SQLite Browser and click 'File -> Open DataBase'
Choose the chinook.db
file from this repo. This database is open source and maintained by Microsoft (SQL is no fun if you don't have any data)
WHAT are the 4 things I can do to data?
How would you return all of the rows in the artists table?
How would you select the artist with the name "Black Sabbath"
SELECT * FROM artists WHERE name = ' Black Sabbath'
How would you create a table named 'fans' with an autoincrementing ID that's a primary key and a name field of type text
CREATE TABLE fans (
id INTEGER PRIMARY KEY ,
name TEXT
)
How would you alter the fans table to have a artist_id column type integer?
ALTER TABLE fans
ADD ArtistId INTEGER
How would you add yourself as a fan of the Black Eyed Peas?
INSERT INTO fans (name)
VALUES (' Anna' )
How would you return fans that are not fans of the black eyed peas.
SELECT * FROM fans
INNER JOIN artists ON
fans .ArtistId = artists .ArtistId
WHERE
artist .Name <> ' Black Eyed Peas'
Display an artists name next to their album title
SELECT artists .Name , albums .Title
FROM artists
INNER JOIN albums ON
artists .ArtistId = albums .ArtistId
Display artist name, album name and number of tracks on that album
SELECT
artists .Name , albums .Title , COUNT (tracks .TrackId ) AS CountTrack
FROM artists
INNER JOIN albums ON
artists .ArtistId = albums .ArtistId
INNER JOIN tracks ON
albums .AlbumId = tracks .AlbumId
GROUP BY artists .Name , albums .Title
How would you return the name of all of the artists in the 'Pop' Genre
SELECT DISTINCT artists .Name
FROM artists
INNER JOIN albums ON
artists .ArtistId = albums .ArtistId
INNER JOIN tracks ON
albums .AlbumId = tracks .AlbumId
INNER JOIN genres ON
tracks .GenreId = genres .GenreId
WHERE genres .Name = ' Pop'
I want to return the names of the artists and their number of rock tracks
who play Rock music
and have move than 30 tracks
in order of the number of rock tracks that they have
from greatest to least
SELECT DISTINCT artists .Name , COUNT (tracks .TrackId ) AS CountTrack
FROM artists
INNER JOIN albums ON
artists .ArtistId = albums .ArtistId
INNER JOIN tracks ON
albums .AlbumId = tracks .AlbumId
INNER JOIN genres ON
tracks .GenreId = genres .GenreId
WHERE genres .Name = ' Rock'
GROUP BY artists .Name
HAVING CountTrack > 30
ORDER BY CountTrack DESC