NEED HELP WITH QUERYhttp://forums.asp.net/t/1794492.aspx/1?NEED+HELP+WITH+QUERYMon, 23 Apr 2012 09:38:35 -040017944924940109http://forums.asp.net/p/1794492/4940109.aspx/1?NEED+HELP+WITH+QUERYNEED HELP WITH QUERY <p>I am trying to setup a query using SqlDataSource for DropDownList</p> <p>This is my problem</p> <p>Table 1 - LocationID, LocationName, CustomerID</p> <p>Table 2 - ContactID, LocationID</p> <p>I am trying to query Table 1 where the data is not in Table 2</p> <p>Select LocationID, LocationName from Table 1 WHERE LocationID is not in Table 2 AND Table1.CustomerID = 1</p> <p>LocationName = Text, LocationID = Value</p> <p>The Setup is that I want to be able to populate the List allowing only those locations, that are not already in Table 2 (mainly because I do not want duplicate records) </p> 2012-04-19T05:36:41-04:004940144http://forums.asp.net/p/1794492/4940144.aspx/1?Re+NEED+HELP+WITH+QUERYRe: NEED HELP WITH QUERY <p>Use one of following QUery</p> <p><strong>select LocationID, LocationName from Tab1</strong><br> <strong>where Tab1.CustomerID = 1 AND&nbsp;Tab1.LocationID not in (select LocationID from Tab2)</strong></p> <p>OR</p> <p><strong>select LocationID, LocationName from Tab1</strong><br> <strong>left outer join Tab2 on Tab1.LocationID&nbsp; = Tab2.LocationID </strong><br> <strong>WHERE ISNULL(Tab2.LocationID,'') ='' AND Tab1.CustomerID = 1</strong></p> 2012-04-19T05:59:12-04:004940154http://forums.asp.net/p/1794492/4940154.aspx/1?Re+NEED+HELP+WITH+QUERYRe: NEED HELP WITH QUERY <p>why dont use distinct keyword? like</p> <pre class="prettyprint">Select distinct LocationID, LocationName from Table .....</pre> <p></p> 2012-04-19T06:05:26-04:004940185http://forums.asp.net/p/1794492/4940185.aspx/1?Re+NEED+HELP+WITH+QUERYRe: NEED HELP WITH QUERY <p>I think Distinct will only help If I have multiple records that are the same, which I do not have in this case. I am trying to retrieve data from one table that is not already in the other table.</p> <p>Example if locations were cookies.</p> <p>If User1 already has a snickerdoodle and an oreo(Table 2), and there are only 3 types of cookies to choose from, then the only selection I would want in the dropdownlist is Chocolate chip(Table 1)</p> <p>this is for security permissions to edit data for users and location info, but only at certain locations. So if a client has 10 locations, but you only want the manager of office a to be able to update info for people at office a, and not b,c,d... but if you have a district manager who is in charge of 5 offices, then you would want him to be able to edit data for those 5 offices. Now if you give him 10 offices, and he is already in charge of 5, then I do not want the person to be able to select the 5 he already has since this would cause duplicate records. In that case I could use distinct, but my database could be full of duplicate records which would not be data friendly if you have 1000 clients and 10,000 records but only really use 4000 because the rest are duplicate.</p> <p></p> 2012-04-19T06:17:07-04:004945941http://forums.asp.net/p/1794492/4945941.aspx/1?Re+NEED+HELP+WITH+QUERYRe: NEED HELP WITH QUERY <p>Hi Bobby,</p> <p>Have you tried @Anil Gaikwad's method? It seems the query will work fine with your data.</p> <p>If your problem still here, please tell us as free.</p> <p>Thanks.</p> 2012-04-23T09:38:35-04:00