{"id":78,"date":"2026-03-06T06:28:58","date_gmt":"2026-03-06T06:28:58","guid":{"rendered":"https:\/\/gigz.pk\/sql\/?post_type=lesson&#038;p=78"},"modified":"2026-03-16T18:50:44","modified_gmt":"2026-03-16T18:50:44","slug":"right-join","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/sql\/lesson\/right-join\/","title":{"rendered":"RIGHT JOIN"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A <strong>RIGHT JOIN<\/strong> is used to combine rows from two tables. It returns all rows from the <strong>right table<\/strong> and the matched rows from the <strong>left table<\/strong>. If there is no match, the result contains <code>NULL<\/code> for columns from the left table.<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773567594339\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT column_list<br>FROM left_table<br>RIGHT JOIN right_table<br>ON left_table.column_name = right_table.column_name;<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>left_table<\/strong>: The first table in the query.<\/li>\n\n\n\n<li><strong>right_table<\/strong>: The second table. All rows from this table are returned.<\/li>\n\n\n\n<li><strong>column_list<\/strong>: Columns you want to retrieve.<\/li>\n\n\n\n<li><strong>ON<\/strong>: The condition that specifies how the tables are related.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">How RIGHT JOIN Works<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>SQL starts with the <strong>right table<\/strong>.<\/li>\n\n\n\n<li>For each row in the right table, it finds matching rows in the left table based on the <strong>ON<\/strong> condition.<\/li>\n\n\n\n<li>If a match exists, the columns from both tables are returned.<\/li>\n\n\n\n<li>If no match exists, columns from the left table are filled with <code>NULL<\/code>.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose we have two tables:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Employees<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>EmployeeID<\/th><th>Name<\/th><th>DeptID<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Alice<\/td><td>10<\/td><\/tr><tr><td>2<\/td><td>Bob<\/td><td>20<\/td><\/tr><tr><td>3<\/td><td>Charlie<\/td><td>30<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Departments<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>DeptID<\/th><th>DeptName<\/th><\/tr><\/thead><tbody><tr><td>10<\/td><td>HR<\/td><\/tr><tr><td>20<\/td><td>Finance<\/td><\/tr><tr><td>40<\/td><td>IT<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Query:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT Employees.Name, Departments.DeptName<br>FROM Employees<br>RIGHT JOIN Departments<br>ON Employees.DeptID = Departments.DeptID;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Result:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Name<\/th><th>DeptName<\/th><\/tr><\/thead><tbody><tr><td>Alice<\/td><td>HR<\/td><\/tr><tr><td>Bob<\/td><td>Finance<\/td><\/tr><tr><td>NULL<\/td><td>IT<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Explanation: The IT department has no matching employee, so <code>Name<\/code> shows <code>NULL<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Key Points<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RIGHT JOIN ensures <strong>all records from the right table<\/strong> appear in the results.<\/li>\n\n\n\n<li>Use RIGHT JOIN when the right table is your main reference and you want all its data, even if the left table has no matches.<\/li>\n\n\n\n<li><code>NULL<\/code> appears in unmatched columns from the left table.<\/li>\n\n\n\n<li>RIGHT JOIN can be rewritten as LEFT JOIN by swapping the table positions.<\/li>\n<\/ul>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/sql\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">SQL Foundations Program (SQL-101) > Basic Joins > RIGHT JOIN<\/span><\/span><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":26,"template":"","class_list":["post-78","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>RIGHT JOIN - SQL Learning Hub<\/title>\n<meta name=\"description\" content=\"Learn SQL RIGHT JOIN: combine tables, return all right table rows, handle NULLs, and see clear examples and syntax.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/sql\/lesson\/right-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RIGHT JOIN - SQL Learning Hub\" \/>\n<meta property=\"og:description\" content=\"Learn SQL RIGHT JOIN: combine tables, return all right table rows, handle NULLs, and see clear examples and syntax.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/sql\/lesson\/right-join\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Learning Hub\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-16T18:50:44+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/right-join\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/right-join\\\/\",\"name\":\"RIGHT JOIN - SQL Learning Hub\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\"},\"datePublished\":\"2026-03-06T06:28:58+00:00\",\"dateModified\":\"2026-03-16T18:50:44+00:00\",\"description\":\"Learn SQL RIGHT JOIN: combine tables, return all right table rows, handle NULLs, and see clear examples and syntax.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/right-join\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/right-join\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/right-join\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Foundations Program (SQL-101) > Basic Joins > RIGHT JOIN\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/\",\"name\":\"SQL Learning Hub\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"RIGHT JOIN - SQL Learning Hub","description":"Learn SQL RIGHT JOIN: combine tables, return all right table rows, handle NULLs, and see clear examples and syntax.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/sql\/lesson\/right-join\/","og_locale":"en_US","og_type":"article","og_title":"RIGHT JOIN - SQL Learning Hub","og_description":"Learn SQL RIGHT JOIN: combine tables, return all right table rows, handle NULLs, and see clear examples and syntax.","og_url":"https:\/\/gigz.pk\/sql\/lesson\/right-join\/","og_site_name":"SQL Learning Hub","article_modified_time":"2026-03-16T18:50:44+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/sql\/lesson\/right-join\/","url":"https:\/\/gigz.pk\/sql\/lesson\/right-join\/","name":"RIGHT JOIN - SQL Learning Hub","isPartOf":{"@id":"https:\/\/gigz.pk\/sql\/#website"},"datePublished":"2026-03-06T06:28:58+00:00","dateModified":"2026-03-16T18:50:44+00:00","description":"Learn SQL RIGHT JOIN: combine tables, return all right table rows, handle NULLs, and see clear examples and syntax.","breadcrumb":{"@id":"https:\/\/gigz.pk\/sql\/lesson\/right-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/sql\/lesson\/right-join\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/sql\/lesson\/right-join\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/sql\/"},{"@type":"ListItem","position":2,"name":"SQL Foundations Program (SQL-101) > Basic Joins > RIGHT JOIN"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/sql\/#website","url":"https:\/\/gigz.pk\/sql\/","name":"SQL Learning Hub","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/sql\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/lesson\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/media?parent=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}