{"id":555,"date":"2022-08-23T21:16:02","date_gmt":"2022-08-23T20:16:02","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/?page_id=555"},"modified":"2022-10-26T13:05:46","modified_gmt":"2022-10-26T12:05:46","slug":"sql-equi-join","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/sql-equi-join\/","title":{"rendered":"SQL &#8211; Equi-Join"},"content":{"rendered":"<p><span data-contrast=\"none\">In SQL, we use a join statement to display results from different tables side by side.<\/span><\/p>\n<p><span data-contrast=\"none\">For example, we might use an Equi-join to display Films and Distributors information together<\/span><\/p>\n<p><span data-contrast=\"none\">An Equi-join works when there is matching data in both tables<\/span><\/p>\n<p><a href=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23195840\/GetImage-3-1.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-511\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23195840\/GetImage-3-1.jpeg\" alt=\"\" width=\"410\" height=\"190\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23195840\/GetImage-3-1.jpeg 410w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23195840\/GetImage-3-1-300x139.jpeg 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>SELECT\u00a0*\u00a0\u00a0<\/strong><\/p>\n<p><strong>FROM Films, Distributors\u00a0<\/strong><\/p>\n<p><strong>Where\u00a0Films.Distributor\u00a0= Distributors.Distributor;\u00a0<\/strong><\/p>\n<p><span style=\"color: #ff0000\">In plain English:\u00a0\u00a0<\/span><\/p>\n<p><span style=\"color: #ff0000\">Show everything from the Films table and join it with the Distributors table.\u00a0\u00a0Joining the records where the\u00a0Distributor field of the Films\u00a0table matches the\u00a0Distributor field of the Distributors table\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210439\/equi.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-556\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210439\/equi.png\" alt=\"\" width=\"1260\" height=\"394\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210439\/equi.png 1260w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210439\/equi-300x94.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210439\/equi-1024x320.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210439\/equi-768x240.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210439\/equi-624x195.png 624w\" sizes=\"auto, (max-width: 1260px) 100vw, 1260px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2><\/h2>\n<h2><span style=\"color: #ff0000\">EQUI-JOIN &#8211; Films.Distributor =Distributors.Distributor<\/span><\/h2>\n<p><a href=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210543\/GetImage-23.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-557\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210543\/GetImage-23.png\" alt=\"\" width=\"562\" height=\"453\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210543\/GetImage-23.png 682w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210543\/GetImage-23-300x242.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23210543\/GetImage-23-624x503.png 624w\" sizes=\"auto, (max-width: 562px) 100vw, 562px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><b><span data-contrast=\"none\"><span style=\"color: #ff0000\">Example<\/span>\u00a0<\/span><\/b><\/p>\n<p><strong>SELECT Title,Rating, [Running Time],\u00a0<span style=\"color: #ff0000\">Distributors<\/span>.Distributor, Founded\u00a0<\/strong><\/p>\n<p><strong>FROM Films, Distributors\u00a0<\/strong><\/p>\n<p><strong>Where\u00a0<span style=\"color: #ff0000\">Distributors<\/span>.Distributor = <span style=\"color: #ff0000\">Films<\/span>.Distributor\u00a0<\/strong><\/p>\n<p><strong>And\u00a0Rating = &#8220;12A&#8221;\u00a0<\/strong><\/p>\n<p><strong>ORDER BY [Running Time] ASC;\u00a0<\/strong><\/p>\n<p><a href=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23211840\/quesry.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-561\" src=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23211840\/quesry.png\" alt=\"\" width=\"885\" height=\"170\" srcset=\"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23211840\/quesry.png 1260w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23211840\/quesry-300x57.png 300w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23211840\/quesry-1024x196.png 1024w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23211840\/quesry-768x147.png 768w, https:\/\/blogs.glowscotland.org.uk\/glowblogs\/public\/phsn5computingscience\/uploads\/sites\/10033\/2022\/08\/23211840\/quesry-624x119.png 624w\" sizes=\"auto, (max-width: 885px) 100vw, 885px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In SQL, we use a join statement to display results from different tables side by side. For example, we might use an Equi-join to display Films and Distributors information together An Equi-join works when there is matching data in both tables &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT\u00a0*\u00a0\u00a0 FROM Films, Distributors\u00a0 Where\u00a0Films.Distributor\u00a0= Distributors.Distributor;\u00a0 In plain English:\u00a0\u00a0 [&hellip;]<\/p>\n","protected":false},"author":79984,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-555","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/pages\/555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/users\/79984"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/comments?post=555"}],"version-history":[{"count":14,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/pages\/555\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/pages\/555\/revisions\/586"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/glowblogs\/phsn5computingscience\/wp-json\/wp\/v2\/media?parent=555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}