SQL - Basic Queries
SQL - Basic Queries
BASIC QUERIES
for non-developer
TOPICS
where A is NULL join A
Condition Multiple tables
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?