0% found this document useful (0 votes)
44 views

SQL - Basic Queries

This document provides an overview of basic SQL queries including selections from single tables, conditions, aggregations, joins across multiple tables, and subqueries. It includes examples of SELECT statements to retrieve columns, use DISTINCT, TOP, WHERE conditions to filter on null values or dates, GROUP BY with aggregate functions, and joins between an Episodes table and Findings table.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

SQL - Basic Queries

This document provides an overview of basic SQL queries including selections from single tables, conditions, aggregations, joins across multiple tables, and subqueries. It includes examples of SELECT statements to retrieve columns, use DISTINCT, TOP, WHERE conditions to filter on null values or dates, GROUP BY with aggregate functions, and joins between an Episodes table and Findings table.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

SQL

BASIC QUERIES
for non-developer
TOPICS
where A is NULL join A
Condition Multiple tables

select * group by A where ID in (select ID ... )


View selection Aggregation Subqueries
SELECTIONS
• SELECT * FROM episodes;
• SELECT TOP 10 * FROM episodes;
• SELECT partyId, partyIdentifierId FROM
episodes;
• SELECT DISTINCT Gender FROM episodes;
Tables
Episode Table Finding Table
Id PartyIdentifier DateOfBirth Genender Id EpisodeId FindingCode Value
Code

1 1 smoker yes
1 10101010101 1971-07-02 female
00:00:00.0000000

2 1 HbA1c 5.69
2 10101010102 2020-07-02 male
00:00:00.0000000

3 2 HbA1c 6
CONDITIONS
• SELECT * FROM episodes WHERE PartyIdentifierId =
'1010101010';
• SELECT * FROM episodes WHERE DateOfBirth IS
NULL;
• SELECT * FROM episodes WHERE DateOfBirth >
'1988-01-01' ORDER BY DateOfBirth DESC
AGGREGATIONS
SELECT episodeId, COUNT(*)
FROM findings f
LEFT JOIN episodes e ON e.Id = f.episodeId
WHERE genderCode= ‘female’
GROUP BY episodeId
HAVING COUNT(*) > 110 ;
MULTIPLE TABLES
SELECT *
FROM episodes e
LEFT JOIN findings f on e.Id = f.episodeId
WHERE PartyIdentifierId = '1010101010';
MULTIPLE TABLES
SELECT *
FROM episodes e
FULL JOIN findings f on e.Id = f.episodeId
WHERE PartyIdentifierId = '1010101010';
SUBQUIRIES
SELECT *
FROM findings
WHERE episodeId in (
SELECT Id
FROM episodes
WHERE genderCode = ‘female’)
Any questions?

You might also like