Skip to content

Instantly share code, notes, and snippets.

@nathanbrauer
Created January 28, 2011 04:12
Show Gist options
  • Save nathanbrauer/799820 to your computer and use it in GitHub Desktop.
Save nathanbrauer/799820 to your computer and use it in GitHub Desktop.
mysql> select * from `Customer` c JOIN (`Order` o) on (c.CustomerID=o.CustomerID) order by c.CustomerID;
+------------+-----------+---------+------------+-----------+
| CustomerID | Name | OrderID | CustomerID | OrderItem |
+------------+-----------+---------+------------+-----------+
| 1 | Nathan | 1 | 1 | boots |
| 2 | James | 5 | 2 | shirt |
| 2 | James | 2 | 2 | socks |
| 3 | Brauer | 6 | 3 | scarf |
| 3 | Brauer | 3 | 3 | pants |
| 4 | The First | 4 | 4 | shorts |
+------------+-----------+---------+------------+-----------+
6 rows in set (0.00 sec)
@sunopensol
Copy link

select * from Customer c left outer JOIN (Order o) on (c.CustomerID=o.CustomerID) order by c.CustomerID;

@nathanbrauer
Copy link
Author

    mysql> select * from Customer c left outer JOIN (`Order` o) on (c.CustomerID=o.CustomerID) order by c.CustomerID;
    +------------+-----------+---------+------------+-----------+
    | CustomerID | Name      | OrderID | CustomerID | OrderItem |
    +------------+-----------+---------+------------+-----------+
    |          1 | Nathan    |       1 |          1 | boots     |
    |          2 | James     |       5 |          2 | shirt     |
    |          2 | James     |       2 |          2 | socks     |
    |          3 | Brauer    |       6 |          3 | scarf     |
    |          3 | Brauer    |       3 |          3 | pants     |
    |          4 | The First |       4 |          4 | shorts    |
    |          5 | Cheeser   |    NULL |       NULL | NULL      |
    +------------+-----------+---------+------------+-----------+
    7 rows in set (0.00 sec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment