{"id":3947,"date":"2025-06-07T08:04:24","date_gmt":"2025-06-07T08:04:24","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3947"},"modified":"2025-06-07T09:58:21","modified_gmt":"2025-06-07T09:58:21","slug":"sql-inner-join","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/sql\/sql-inner-join\/","title":{"rendered":"SQL INNER JOIN"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><code>INNER JOIN<\/code> combines rows from two or more tables <strong>only when matching values exist in both<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Basic Syntax<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT columns\nFROM table1\nINNER JOIN table2\n  ON table1.common_column = table2.common_column;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Example: Employees and Departments<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT\n  e.employee_name,\n  d.department_name\nFROM employees e\nINNER JOIN departments d\n  ON e.department_id = d.department_id;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 This returns only those employees who are assigned to a department.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Join on Multiple Conditions<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT *\nFROM orders o\nINNER JOIN customers c\n  ON o.customer_id = c.customer_id\n  AND o.region = c.region;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Using Table Aliases (Best Practice)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Shortens query and improves readability:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT e.name, d.name\nFROM employees e\nINNER JOIN departments d\n  ON e.dept_id = d.id;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Key Point<\/th><th>Explanation<\/th><\/tr><\/thead><tbody><tr><td><code>INNER JOIN<\/code><\/td><td>Returns only rows with matching values in both tables<\/td><\/tr><tr><td><code>ON<\/code> clause<\/td><td>Defines the join condition<\/td><\/tr><tr><td>Table aliases<\/td><td>Improve clarity and simplify column references<\/td><\/tr><tr><td>Filters<\/td><td>Can be combined with <code>WHERE<\/code>, <code>GROUP BY<\/code>, etc.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd17 Use <code>INNER JOIN<\/code> to extract meaningful data from related tables<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>INNER JOIN combines rows from two or more tables only when matching values exist in both. \ud83d\udd39 Basic Syntax \ud83d\udd39 Example: Employees and Departments \u2705 This returns only those employees who are assigned to a department. \ud83d\udd39 Join on Multiple Conditions \ud83d\udd39 Using Table Aliases (Best Practice) Shortens query and improves readability: \ud83e\udde0 Quick Recap [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,979],"class_list":["post-3947","cposts","type-cposts","status-publish","hentry","category-notes","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/3947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}