The INNER JOIN clause let us match rows with same columns from two different tables. Following rules have to be applied to use the INNER JOIN clause:
- It must be put after FROM clause;
- The first table has to be specified in the FROM clause;
- The second table is specified after the INNER JOIN clause;
- The last is to specify the join condition, which appears after the keyword ON
- Try not to match more than two tables in order to keep the performance up.
Syntax
The following example shows the basic syntax for INNER JOIN clause:
SELECT columns FROM table1 INNER JOIN table2 ON join_conditions ? WHERE where_conditions;
And if you want to add more than two tables, continue previous as shown:
SELECT columns FROM table1
INNER JOIN table2 ON join_conditions1
INNER JOIN table3 ON join_conditions2
...
WHERE where_conditions;
SELECT Table1.itemNumber, status, SUM(quantityOrdered * itemPrice) total
FROM items AS Table1
INNER JOIN itemDetails AS Table2 ON Table1.itemNumber = Table2.itemNumber
GROUP BY itemNumber;
In the example above we can see that the columns, in order to distinguish them from one another, have to be read as Table1.itemNumber and Table2.itemNumber.
Comments
No comments have been made yet.
Please login to leave a comment. Login now