We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
SELECT * FROM (
SELECT
s3.name as Doctor,
s2.name as Professor,
s4.name as Singer,
s1.name as Actor
FROM
(SELECT rn, name FROM occ_n WHERE occ = 'Doctor') s3
LEFT JOIN
(SELECT rn, name FROM occ_n WHERE occ = 'Professor') s2 ON s3.rn = s2.rn
LEFT JOIN
(SELECT rn, name FROM occ_n WHERE occ = 'Singer') s4 ON s3.rn = s4.rn
LEFT JOIN
(SELECT rn, name FROM occ_n WHERE occ = 'Actor') s1 ON s3.rn = s1.rn
UNION
SELECT
s3.name as Doctor,
s2.name as Professor,
s4.name as Singer,
s1.name as Actor
FROM
(SELECT rn, name FROM occ_n WHERE occ = 'Doctor') s3
RIGHT JOIN
(SELECT rn, name FROM occ_n WHERE occ = 'Professor') s2 ON s3.rn = s2.rn
RIGHT JOIN
(SELECT rn, name FROM occ_n WHERE occ = 'Singer') s4 ON s3.rn = s4.rn
RIGHT JOIN
(SELECT rn, name FROM occ_n WHERE occ = 'Actor') s1 ON s3.rn = s1.rn
) x
ORDER BY Doctor, Professor, Singer, Actor;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Occupations
You are viewing a single comment's thread. Return to all comments →
SELECT * FROM ( SELECT s3.name as Doctor, s2.name as Professor, s4.name as Singer, s1.name as Actor FROM (SELECT rn, name FROM occ_n WHERE occ = 'Doctor') s3 LEFT JOIN (SELECT rn, name FROM occ_n WHERE occ = 'Professor') s2 ON s3.rn = s2.rn LEFT JOIN (SELECT rn, name FROM occ_n WHERE occ = 'Singer') s4 ON s3.rn = s4.rn LEFT JOIN (SELECT rn, name FROM occ_n WHERE occ = 'Actor') s1 ON s3.rn = s1.rn UNION SELECT s3.name as Doctor, s2.name as Professor, s4.name as Singer, s1.name as Actor FROM (SELECT rn, name FROM occ_n WHERE occ = 'Doctor') s3 RIGHT JOIN (SELECT rn, name FROM occ_n WHERE occ = 'Professor') s2 ON s3.rn = s2.rn RIGHT JOIN (SELECT rn, name FROM occ_n WHERE occ = 'Singer') s4 ON s3.rn = s4.rn RIGHT JOIN (SELECT rn, name FROM occ_n WHERE occ = 'Actor') s1 ON s3.rn = s1.rn ) x ORDER BY Doctor, Professor, Singer, Actor;