Linkr
Home Resources Tools Documentation Blog Demo
FR
Learn programming
  • Why learn to code?
  • Programming fundamentals
  • Introduction to SQL
3/5
10 min Boris Delange, Martin Castan, Lou Vignais · 02/07/2026

Introduction to SQL

What SQL is for, the language of databases. SELECT, WHERE, JOIN, GROUP BY illustrated on health data, plus free resources to practise.

In a nutshell

SQL (Structured Query Language) is the universal language for querying a database. It is the gateway to data in a clinical data warehouse: you use it to choose columns, filter rows, link tables and aggregate. Five keywords cover the essentials: SELECT, FROM, WHERE, JOIN, GROUP BY.

If you haven’t yet read Why learn to code?, it places SQL among the other languages. In short: the data in a clinical data warehouse (CDW) is stored in a database, and SQL is the language that pulls out what you need.

What a database looks like

A database is like a binder with several linked sheets — what we call tables, described in detail in the article on data organization. Let’s take two tables inspired by the OMOP model:

Table person (patients)

person_idyear_of_birthgender
11951F
21978M
31990F

Table measurement (creatinine)

person_idvaluedate
11422023-04-02
11282023-04-05
2882023-06-11

Each table has a key (here person_id) that links it to the others. Writing SQL means describing to the database what you want to see from these tables.

The four basic moves

SELECT and FROM — choose the columns of a table

SELECT states which columns to display, and FROM from which table. The * means “all columns”.

SQL
-- Only the identifier and the year of birth
SELECT person_id, year_of_birth
FROM person;
Result
person_idyear_of_birth
11951
21978
31990

Comments

A line starting with -- is a comment: it is ignored by the database and serves to explain the code to humans. The tutorials below will have you write your first queries live.

WHERE — filter the rows

WHERE keeps only the rows that meet a condition.

SQL
-- Female patients born before 1960
SELECT person_id, year_of_birth
FROM person
WHERE gender = 'F'
AND year_of_birth < 1960;
Result
person_idyear_of_birth
11951

AND combines several conditions: a row is kept only if it meets all of them. Here, a patient must be female and born before 1960. Its counterpart OR keeps the rows that meet at least one of the conditions.

Read a query like a sentence

A query reads almost like a sentence. This one translates literally as: select the columns person_id and year_of_birth from the table person, where sex is F and the year of birth is less than 1960.

This is exactly the move you make with a filter in a spreadsheet — filtering on rows and columns — but written once, reproducibly, and applicable to millions of rows.

JOIN — link the tables

A patient’s data is spread across several tables. JOIN brings them together using the shared key.

SQL
-- Associate each creatinine measurement with the matching patient
SELECT p.person_id, p.year_of_birth, m.value, m.date
FROM person AS p
JOIN measurement AS m
ON p.person_id = m.person_id;
Result
person_idyear_of_birthvaluedate
119511422023-04-02
119511282023-04-05
21978882023-06-11

Here p and m are nicknames (aliases) given to the tables to shorten the writing. The condition ON p.person_id = m.person_id tells the database how to match rows from the two tables.

GROUP BY — aggregate

GROUP BY groups rows to compute statistics per group: a count, a mean, a maximum…

SQL
-- Number of measurements and mean creatinine, per patient
SELECT person_id,
     COUNT(*)    AS n_measurements,
     AVG(value)  AS mean_creatinine
FROM measurement
GROUP BY person_id;
Result
person_idn_measurementsmean_creatinine
12135.0
2188.0

COUNT(*) counts the rows of each group, and AVG (short for average) computes their mean. Other functions follow the same principle: MIN, MAX, SUM. The word AS gives the computed column a name.

Putting it all together. A realistic query combines these four moves. For example: “for each female patient over 65, the maximum creatinine measured in 2023”.

SQL
SELECT p.person_id,
     MAX(m.value) AS max_creatinine
FROM person AS p
JOIN measurement AS m
ON p.person_id = m.person_id
WHERE p.gender = 'F'
AND (2023 - p.year_of_birth) > 65
AND m.date BETWEEN '2023-01-01' AND '2023-12-31'
GROUP BY p.person_id;
Result
person_idmax_creatinine
1142

You select (SELECT), link (JOIN), filter (WHERE) and group (GROUP BY). That is the skeleton of most extractions.

Resources to learn

SQL is learned by writing queries, not by reading them. Here are two free, progressive resources to practise directly in the browser, with nothing to install.

W3Schools — SQL Tutorial
Type: Interactive tutorial Language: English Cost: Free Duration: ~6 h Level: Beginner Prerequisites: None

What you'll learn

  • All the core syntax: SELECT, WHERE, JOIN, GROUP BY and aggregate functions.
  • A “Try it Yourself” button that runs your queries on a real database, in real time.
  • Great for a first contact and to check syntax.
SQLBolt
Type: Interactive exercises Language: English Cost: Free Duration: ~4 h Level: Beginner to intermediate Prerequisites: None

What you'll learn

  • Short lessons followed by graded exercises, to do in order.
  • Difficulty rising step by step, up to joins and subqueries.
  • Perfect to practise after a first read of the syntax.

Recommended path for SQL

  1. Go through W3Schools to discover the syntax (~6 h).
  2. Consolidate with the SQLBolt exercises (~4 h).
  3. Apply SQL to real health data with our interactive OMOP tutorials, which run SQL on a MIMIC database in the browser (beginner then intermediate).

Count on about ten hours in total to get comfortable.

SQL and Linkr

In Linkr, the Study Designer automatically generates the SQL matching the inclusion criteria and variables you define with the mouse. Being able to read that SQL helps you verify what the tool is doing and take back control for specific needs.

  • SQL queries databases: it is the gateway to data in a warehouse.
  • Five keywords cover the essentials: SELECT (columns), FROM (table), WHERE (rows), JOIN (link tables), GROUP BY (aggregate).
  • A realistic extraction combines these four moves in a single query.
  • W3Schools and SQLBolt let you practise for free in the browser; the OMOP tutorials apply SQL to health data.
  • Linkr's Study Designer generates the SQL for you — reading it helps you verify and go further.
Next article : Introduction to R

About the author

View profile
Boris Delange
Boris Delange

Intensive-care physician · academic lecturer in medical informatics

Trained in intensive care medicine, I have worked since 2023 as an academic lecturer in medical informatics at the Clinical Data Centre (CDC) of Rennes University Hospital. I am also a researcher at LTSI (University of Rennes), in the DOMASIA team (Massive Data and Learning Health Information Systems).

Working at the crossroads of care and data science, I created Linkr to connect clinicians, data scientists, engineers and health students around healthcare data analysis.

View LinkedIn profile View ResearchGate profile
PreviousProgramming fundamentals

Product

  • Home
  • Demo

Resources

  • Documentation
  • Resources
  • Tools
  • Blog

Community

  • Framagit source code
  • Github source code

About

  • InterHop.org
  • Contact

2021–2026 InterHop — CC BY-NC-SA 4.0 (site) · GPLv3 (software)