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

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
SQL snippets
Cosmo
Sign Up Now
or Subscribe for future quizzes