﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Luigi Marinescu  / JOIN technique / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 13:15:56 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: JOIN technique</title><link>http://www.sqlservercentral.com/Forums/Topic823015-1683-1.aspx</link><description>HiLet's consider next case:Tables: Sales 1&amp;lt;--&amp;gt; m Products 1&amp;lt;--&amp;gt;1 Country[code="sql"]Select *FROM   Sales s   inner join Products p on s.ProductId = p.ProductId   inner join Country c on p.MadeInCountryId = c.CountryIdWHERE CountryName like 'A%'[/code]OR [code="sql"]Select *FROM   Sales s   inner join Products p          inner join Country c on p.MadeInCountryId = c.CountryId   on s.ProductId = p.ProductIdWHERE CountryName like 'A%'[/code]</description><pubDate>Mon, 07 Dec 2009 13:39:52 GMT</pubDate><dc:creator>halford13</dc:creator></item><item><title>RE: JOIN technique</title><link>http://www.sqlservercentral.com/Forums/Topic823015-1683-1.aspx</link><description>Hi,Sorry, I should have usedSales s			INNER JOIN	Products p on c.ProductId = p.ProductIdnot CustomerId ... Thanks,Luigi</description><pubDate>Mon, 07 Dec 2009 13:32:09 GMT</pubDate><dc:creator>halford13</dc:creator></item><item><title>RE: JOIN technique</title><link>http://www.sqlservercentral.com/Forums/Topic823015-1683-1.aspx</link><description>Why not pass in XML into the SP? I.e.@BrandId_List XML --e.g. &amp;lt;Brands&amp;gt;&amp;lt;id&amp;gt;1&amp;lt;/id&amp;gt;&amp;lt;id&amp;gt;2&amp;lt;/id&amp;gt;&amp;lt;/Brands&amp;gt;And then your query could look like this:SELECT *	FROM 		Sales s			INNER JOIN	Products p on s.customerId = p.customerId			INNER JOIN	Brands b on p.BrandId = b.BrandId 	WHERE		tb.BrandId IN (SELECT Brands.ID.value('.','INT')				FROM @BrandId_List.nodes('/Brands/id') AS Brands(ID))OR @BrandID_List IS NULLBy passing NULL for the parameter would still achieve the same result; you would just have to build the XML before passing into the SP. Also worth noting that you can apply an XML namespace here to make sure your XML markup conforms to a set standard.</description><pubDate>Mon, 07 Dec 2009 09:38:27 GMT</pubDate><dc:creator>Joukahainen</dc:creator></item><item><title>RE: JOIN technique</title><link>http://www.sqlservercentral.com/Forums/Topic823015-1683-1.aspx</link><description>Not sure why you'd want your Products table to have a customerId column. If you have to track which customers have which products, I'd think that would be in a table other than Products.</description><pubDate>Mon, 07 Dec 2009 09:22:08 GMT</pubDate><dc:creator>Rob-506957</dc:creator></item><item><title>RE: JOIN technique</title><link>http://www.sqlservercentral.com/Forums/Topic823015-1683-1.aspx</link><description>Personally, I would use dynamic SQL instead for best performance since the impact of indexes would be quite different depending on the Brand_IDs passed in.  I also believe that you need to add a FORCE ORDER query hint in order to make sure that the query optimizer respects the difference in join order between your two options.</description><pubDate>Mon, 07 Dec 2009 08:59:44 GMT</pubDate><dc:creator>Tim Overlund</dc:creator></item><item><title>JOIN technique</title><link>http://www.sqlservercentral.com/Forums/Topic823015-1683-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/JOIN/68746/"&gt;JOIN technique&lt;/A&gt;[/B]</description><pubDate>Sun, 22 Nov 2009 14:26:11 GMT</pubDate><dc:creator>halford13</dc:creator></item></channel></rss>