DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
LΓ’m
LΓ’m

Posted on

Sql Joins Cheat Sheet

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

Top comments (1)

Collapse
 
socoladaica profile image
Socola Đẑi Ca • Edited on

Advanced

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.