YOUR AD GOES HERE

day 44 | 50 Days of SQL | SELECT, AS, FROM, UNION ALL | SQL Query

Published 09, Dec 2023

SAHAS H S


Description:
Combining Patient and Doctor Data Using SQL UNION


The hospital.sqlite database consists of multiple tables, but for this challenge, you will primarily be focused on two tables:

patients
doctors
Each table represents different roles within a hospital: "Patient" and "Doctor".

Task Description
Your challenge is to retrieve the first_name, last_name, and role of every person present in both the patients and doctors tables. You must ensure that the role for each person is correctly labeled as either "Patient" or "Doctor". Make sure to name this column as "role"

Key Concepts
UNION: SQL's UNION clause allows you to combine rows from two or more tables based on a related column. The primary condition is that the columns should be of the same datatype.
ALIAS: In SQL, aliases are used to give a temporary name to a table or a column for the purpose of a specific SQL query. It can be beneficial for making column names more readable.
Good luck with your task! Remember, practice makes perfect.

Query:
elect first_name,last_name,'Patient' as 'role' from patients
union all
select first_name,last_name,'Doctor' as 'role' from Doctors;

#codedamn #challenge #solution #sql #50dayschallenge #query

Releted More Videos

You May Also Like

YOUR AD GOES HERE

YOUR AD GOES HERE