DEV Community

loading...

Sql Joins Cheat Sheet

Lâm
・1 min read

Diagram

SELECT * FROM `A` INNER JOIN `B`
Enter fullscreen mode Exit fullscreen mode
┌────────┐
│ A  ┌───┼────┐
│    │ ∩ │    │
└────┼───┘  B │
     └────────┘
Enter fullscreen mode Exit fullscreen mode
Join What
Inner join
Left outer join A +
Right outer join + B
Full outer join A + + B

Example

SELECT * FROM order_items \
  LEFT OUTER JOIN orders \
  ON order_items.order_id = orders.id
Enter fullscreen mode Exit fullscreen mode

Joins are typically added to SELECT statements to add more columns and records.

Reference

Discussion (1)

Collapse
socoladaica profile image
Socola Đại Ca • Edited

Advanced