MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 24th, 2012, 06:01 AM
madork madork is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Location: London
Posts: 3 madork User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 31 sec
Reputation Power: 0
Return values not in joined table

Hello,
I'm relatively new so please ignore my ignorance and amateur skills.

Basically, I'm looking to pull back some results but not include those that have a value in a column that matches a value in a temp table.

(I can't figure out how to make this wrapped like code)
------Folder Differences-----
--Create Temp Table--
CREATE TABLE #fdiff

(foldername VARCHAR(255))

SELECT
replace(
replace(foldername,'[Template] ','')
, '[Archive Template] ','') AS Foldername

FROM
folderproperties FP with (nolock)
WHERE domainid ='39'

--Folder Differences--
SELECT dp.Domainname, dp.Domainid, fp.Foldername, fd.[foldername]

FROM DomainProperties DP with (nolock) Inner join
folderproperties FP with (nolock) on dp.Domainid = fp.domainid left outer join
#fdiff fd with (nolock) on fp.[foldername] = fd.[foldername]

WHERE
NOT EXISTS (select foldername From #fdiff )
AND
dp.Domainid NOT IN ('39','1','2','58')

DROP TABLE #fdiff

Reply With Quote
  #2  
Old July 24th, 2012, 06:10 AM
deljr deljr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Location: Wisconsin
Posts: 78 deljr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 51 m 6 sec
Reputation Power: 2
try something like this

Code:
SELECT table1.column1, table1.column2 FROM table1 WHERE table1.column2 NOT IN (SELECT table2.column1 FROM table2)


use the main query to get your data and the sub query to point to the temp table

Try to start simple if your still new to this. If a simple query like my example gets you the data you want build off that.

Reply With Quote
  #3  
Old July 24th, 2012, 06:43 AM
madork madork is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Location: London
Posts: 3 madork User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 31 sec
Reputation Power: 0
Thanks, I started off with something like this and still had issues. See the below.

Code:
CREATE TABLE #fdiff (foldername VARCHAR(255)) SELECT replace( replace(foldername,'[Template] ','') , '[Archive Template] ','') AS Foldername FROM folderproperties FP with (nolock) WHERE domainid ='39' SELECT FP.FolderName FROM folderproperties FP with (nolock) WHERE FP.[foldername] NOT IN (Select #fdiff.[foldername] FROM #fdiff) DROP TABLE #fdiff




Quote:
Originally Posted by deljr
try something like this

Code:
SELECT table1.column1, table1.column2 FROM table1 WHERE table1.column2 NOT IN (SELECT table2.column1 FROM table2)


use the main query to get your data and the sub query to point to the temp table

Try to start simple if your still new to this. If a simple query like my example gets you the data you want build off that.

Reply With Quote
  #4  
Old July 24th, 2012, 06:57 AM
deljr deljr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Location: Wisconsin
Posts: 78 deljr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 51 m 6 sec
Reputation Power: 2
just to confirm you are using mysql correct?

just looked into your query and (no lock) is a mssql command...

Reply With Quote
  #5  
Old July 24th, 2012, 07:00 AM
madork madork is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Location: London
Posts: 3 madork User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by deljr
just to confirm you are using mysql correct?

just looked into your query and (no lock) is a mssql command...


I am using MSSQL apologies, I assumed they were all pretty similar when it comes to basics like this.

Reply With Quote
  #6  
Old July 24th, 2012, 07:23 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,442 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 14 h 16 m 32 sec
Reputation Power: 4141
Quote:
Originally Posted by madork
I am using MSSQL apologies, I assumed they were all pretty similar when it comes to basics like this.
um... no

thread moved to sql server forum
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #7  
Old July 24th, 2012, 07:30 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,442 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 14 h 16 m 32 sec
Reputation Power: 4141
Code:
SELECT dp.Domainname
     , dp.Domainid
     , fp.Foldername
     , fd.[foldername]
  FROM DomainProperties DP with (nolock) 
Inner 
  join folderproperties FP with (nolock) 
    on fp.domainid = dp.Domainid
left outer 
  join #fdiff fd with (nolock) 
    on fd.[foldername] = fp.[foldername]
 WHERE dp.Domainid NOT IN ('39','1','2','58')
   AND fd.[foldername] IS NULL

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Return values not in joined table

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap