Created
September 13, 2019 23:14
-
-
Save zaynkorai/b20e9935a23bd0fdfe50b4a504b5e9b9 to your computer and use it in GitHub Desktop.
Sample Task SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Task 1 | |
ALTER TABLE mapping | |
ADD CONSTRAINT mapping_fk_1 FOREIGN KEY (user_id) REFERENCES users (id), | |
ADD CONSTRAINT mapping_fk_2 FOREIGN KEY (program_id) REFERENCES programs (id); | |
#Task 2 | |
Select u.name as 'User', p.name as 'Program' from users u | |
INNER JOIN mapping m ON u.id = m.user_id | |
INNER JOIN programs p on m.program_id = p.id; | |
#Task 3 | |
Select u.name as 'User', p.name as 'Program' from users u | |
INNER JOIN mapping m ON u.id = m.user_id | |
INNER JOIN programs p on m.program_id = p.id | |
WHERE m.dated > DATE_SUB(NOW(), INTERVAL 10 MINUTE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment