Work in pairs. Start by forking this repo, and making sure you both have access to the fork. Clone the repo to one of your laptops. Pair on this in driver navigator style, but swap around for each task.
For each task below, find a single sql query that returns the correct
result. Add it do this document in the ```sql ```
blocks, plus any notes.
Make sure your changes are commited and pushed when you finish.
SELECT name FROM channel
WHERE creator_id = 2
SELECT * FROM message
WHERE channel_id = 5
ORDER BY posted_at DESC
LIMIT 5;
SELECT * FROM message
WHERE channel_id = 11
ORDER BY posted_at ASC
LIMIT 10;
SELECT name, email FROM user
WHERE is_admin = 1;
SELECT name FROM user
WHERE is_admin = 0 AND is_bot = 0;
SELECT * FROM message
INNER JOIN channel ON channel_id = channel_id
WHERE name = "resources";
SELECT name FROM channel_member
INNER JOIN user ON id = user_id
WHERE channel_id = 15;
Use your email address as part of your WHERE
- don't query by your user id.
SELECT channel.name FROM channel
INNER JOIN user ON user.id = user_id
INNER JOIN channel_member ON channel.id = channel_id
WHERE email = "stuart.priestley@ada.ac.uk"
SELECT COUNT() FROM message;
10: Create a query that returns the text of each message, the name of the channel it was posted in, and the name of the poster, in chronological order
Hint: there should be the same number of results as there are messages - use this to manually check the results you're getting!
SELECT message.text, channel.name, user.name FROM message
INNER JOIN channel ON channel.id = channel_id
INNER JOIN user ON user.id = user_id
ORDER BY posted_at ASC;
SELECT name, COUNT(text) as message FROM message
INNER JOIN user ON user.id = user_id
GROUP BY "name"
ORDER BY "message" DESC
LIMIT 5
12: Find the names of every user who has never sent a message that didn't end with 'has joined the channel'
SELECT name FROM user
LEFT JOIN message ON user.id = message.user_id
WHERE text IS NULL