AdvancedTopic 75 of 104Software & Computing

SQL queries and joins

SELECT, JOIN and GROUP BY retrieve and aggregate data.

In depth

SELECT retrieves data with WHERE, GROUP BY, HAVING and ORDER BY; JOINs (INNER, LEFT, RIGHT, FULL) combine tables; aggregates (COUNT, SUM, AVG); subqueries and window functions enable analytics. Avoid SQL injection by using parameterised queries.

Key points

  • Query planner
  • Set operations
  • CTEs
Example

SELECT c.name, SUM(o.total) FROM customers c JOIN orders o ON o.cid=c.id GROUP BY c.name.

Why it matters

SQL lets you ask questions of relational data, and joins and grouping turn raw tables into useful answers.

Where this is used

  • Finding the total sales per region with GROUP BY.
  • Joining orders to customers to list who bought what.
  • Selecting the last hundred sensor readings from a table.

Frequently asked questions

What is SQL queries and joins?

SELECT, JOIN and GROUP BY retrieve and aggregate data.

Why is it important to understand SQL queries and joins?

SQL lets you ask questions of relational data, and joins and grouping turn raw tables into useful answers.

What does a JOIN do?

It combines rows from two tables where the join condition matches, which lets you use related data in one result.

What is the difference between WHERE and HAVING?

WHERE filters individual rows before grouping, while HAVING filters the groups after aggregation.

How is SQL queries and joins used in practice?

Typical applications include finding the total sales per region with GROUP BY, joining orders to customers to list who bought what and selecting the last hundred sensor readings from a table.

What should I learn before SQL queries and joins?

Study "Relational databases" first (topic 74 of 104 in Software & Computing). It covers the groundwork this topic builds on.

What are the key points of SQL queries and joins?

Query planner. Set operations. CTEs.

Can you give an example of SQL queries and joins?

SELECT c.name, SUM(o.total) FROM customers c JOIN orders o ON o.cid=c.id GROUP BY c.name.

What comes after SQL queries and joins?

The next topic is "Normalisation", which builds directly on this one.

How difficult is SQL queries and joins?

It is classed as Advanced in Software & Computing (topic 75 of 104). It is an advanced topic. It assumes you are comfortable with the intermediate topics in Software & Computing.

Learning path

Want to practise? Open the interactive course for quick checks, quizzes, simulations and progress tracking.

Related topics