AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL Inner Join |
|
SQL > SQL JOIN >
Inner Join
An inner join in SQL returns rows where there is at least one match on both tables. Let's assume that we have the following two tables,
Key Takeaway: INNER JOIN is the most common join type. It returns only rows where the join condition is met in both tables — rows without a match in either table are excluded from results.
Table Store_Information
Table Geography
We want to find out sales by store, and we only want to see stores with sales listed in the result set. To do this, we can use the following SQL statement using INNER JOIN: Result:
By using INNER JOIN, the result shows 3 stores, even though we are selecting from the Geography table, which has 4 rows. The row "New York" is not selected because it is not present in the Store_Information table. Frequently Asked QuestionsWhy does INNER JOIN exclude "New York" in the example above?"New York" appears in the Geography table but not in Store_Information. Because INNER JOIN requires a match in both tables, rows with no matching entry are excluded from the result set. Can INNER JOIN be used with more than two tables?Yes. You can chain multiple INNER JOINs: What is the difference between INNER JOIN and CROSS JOIN?INNER JOIN returns only matching rows (filtered by the ON condition). CROSS JOIN returns the Cartesian product of both tables — every row from the first table paired with every row from the second — no condition needed. Does INNER JOIN affect performance?Yes. JOINs can be expensive on large tables. Ensure that the columns used in the ON condition are indexed for best performance.
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.