SQL INNER JOIN

SQL INNER JOIN return rows when there is at least one match in both tables

Syntax

SELECT * FROM table_name1 INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name

MySQL Table – users
|+—-+——+
| id | name |
+—-+——+
|  1 | AAAA |
|  2 | BBBB |
|  3 | CCCC |
|  4 | DDDD |
|  5 | EEEE |
+—-+——+

MySQL Table – Orders

+—–+—–+——–+
| oid | uid | items  |
+—–+—–+——–+
|   1 |   1 | Pen    |
|   2 |   2 | Watch  |
|   3 |   3 | shoe   |
|   4 |   4 | mobile |
+—–+—–+——–+

Example

mysql> SELECT u.name,o.items FROM users as u INNER JOIN orders as o ON u.id=o.uid ;
+——+——–+
| name | items  |
+——+——–+
| AAAA | Pen    |
| BBBB | Watch  |
| CCCC | shoe   |
| DDDD | mobile |
+——+——–+
4 rows in set (0.00 sec)

Share