SQL Daily Practice — Day 15
Hello, Connections, Data Professionals and SQL Enthusiasts.
It’s the 15th day of our daily practice on SQL-PRACTICE-DOT-COM.
We had a day break yesterday.
Follow Olawale Ahmed Alamu and #sqldailyupdates for #day1 to #day14 and daily updates.
Today, we are looking at the SQL DISTINCT keyword that is used to SELECT unique values on a column of a table in a database.
QUESTION: Based on the cities that our patients live in, show unique cities that are province_id: ‘NS’.
PROBLEM ANALYSIS: We are to output unique cities of patients living within the province with the province_id: ‘NS’.
SOLUTION: We write a SELECT DISTINCT statement to output the unique cities with a WHERE clause of the province with province_id: ‘NS’.
SQL CODE:
— — — — — —
SELECT
DISTINCT cities as unique_cities FROM patients
WHERE province_id = ‘NS’
— — — — — —
Link to practice in the comments section.
Screenshot image of the SQL Script and solution output is attached below: