INNER JOINs

SQL: SELECT: Joins and Sets

INNER JOINs return rows that match from both tables.

SELECT <columns> FROM <table 1> 
    INNER JOIN <table 2> ON <table 1>.<column> = <table 2>.<column>;

SELECT <columns> FROM <table 1> AS <table 1 alias> 
    INNER JOIN <table 2> AS <table 2 alias> ON <table 1 alias>.<column> = <table 2 alias>.<column>;

//or, for multiple tables

SELECT <columns> FROM <table 1> 
    INNER JOIN <table 2> ON <table 1>.<column> = <table 2>.<column>
    INNER JOIN <table 3> ON <table 1>.<column> = <table 3>.<column>;

Example:

SELECT product_name, category FROM products
    INNER JOIN product_categories ON products.category_id = product_categories.id;

SELECT products.product_name, product_categories.category FROM products
    INNER JOIN product_categories ON products.category_id = product_categories.id;

SELECT p.product_name, c.category FROM products AS p
    INNER JOIN product_categories AS c ON p.category_id = c.id;

//or, for multiple tables

SELECT users.full_name, sales.amount, products.name FROM sales 
        INNER JOIN users ON sales.user_id = users.id
        INNER JOIN products ON sales.product_id = products.id;