Created
October 5, 2022 03:22
-
-
Save rosousa/128d37db816db73164c2c384b5262ec3 to your computer and use it in GitHub Desktop.
Prática - Exercícios Join
This file contains hidden or 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
--Q1: | |
SELECT users.id, users.name, cities.name AS city FROM users JOIN cities ON users."cityId" = cities.id WHERE cities.name = 'Rio de Janeiro'; | |
--Q2: | |
SELECT testimonials.id, writer.name AS writer, recipient.name AS recipient, testimonials.message FROM testimonials JOIN users AS "writer" ON testimonials."writerId" = writer.id JOIN users AS recipient ON testimonials."recipientId" = recipient.id; | |
--Q3: | |
SELECT educations."userId" AS id, users.name, courses.name AS course, schools.name AS school, educations."endDate" FROM educations JOIN courses ON educations."courseId" = courses.id JOIN users ON educations."userId" = users.id JOIN schools ON educations."schoolId" = schools.id WHERE educations."userId" = 30 AND educations.status = 'finished'; | |
--Q4: | |
SELECT users.id, users.name, roles.name AS role, companies.name AS company, experiences."startDate" FROM experiences JOIN companies ON experiences."companyId" = companies.id JOIN users ON experiences."userId" = users.id JOIN roles ON experiences."roleId" = roles.id WHERE experiences."userId" = 50 AND experiences."endDate" IS NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment