‹ BACK

Example - INNER JOINS

Example - INNER JOINS

(a) CUSTOMERS table is as follows:
| ID | NAME     |
+----+----------+
|  1 | Ramesh   |
|  2 | Khilan   |
|  3 | kaushik  |
|  4 | Chaitali |
|  5 | Hardik   |
|  6 | Komal    |
(b) Another table is ORDERS as follows:
| OID |  ID | AMOUNT |
+-----+-----+--------+
| 102 |   3 |   3000 |
| 100 |   3 |   1500 |
| 101 |   2 |   1560 |
| 103 |   4 |   2060 |
Now, let us join these two tables using INNER JOIN as follows:
SQL> SELECT  ID, NAME, AMOUNT
     FROM CUSTOMERS
     INNER JOIN ORDERS
     ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;
This would produce the following result:
| ID | NAME     | AMOUNT |
+----+----------+--------+
|  3 | kaushik  |   3000 |
|  3 | kaushik  |   1500 |
|  2 | Khilan   |   1560 |
|  4 | Chaitali |   2060 |
Read more: SQL - INNER JOINS
join inner-join

To check your knowledge the following tests are recommended:
Check your sql sql skills.