YouTip LogoYouTip

MySQL Joins and Aggregation

Joins

SELECT users.name, orders.product
FROM users
INNER JOIN orders ON users.id = orders.user_id;

SELECT users.name, orders.product
FROM users
LEFT JOIN orders ON users.id = orders.user_id;

Aggregation

SELECT age, COUNT(*) as count FROM users GROUP BY age;
SELECT SUM(amount) FROM orders WHERE user_id = 1;

Summary

  • INNER JOIN returns matching rows from both tables
  • LEFT JOIN returns all rows from left table
← SQL Tutorial - Basic QueriesMySQL Tutorial - Getting Start β†’