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

Reply
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 April 27th, 2012, 06:43 AM
dwair dwair is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 53 dwair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 14 m 50 sec
Reputation Power: 8
Left Join / Join SQL Help need

Left Join / Join SQL Help need listing records that are not present

Using SQL Express 5 I’m trying to list entry’s from one table that aren’t listed in another table. Using the example below, Property 1 has a row for all imorder’s but property 2 does not have a row containing imorder = 3 and property 3 does not have a row containing imorder = 2. I want to list these two rows in my query.

I have tried various joins, left and right joins and not exists but I don’t seem to be able to make it work despite it seeming like a very basic thing to do.

Any help gratefully received!

Table: property
adId adpropname
1 property1
2 property2
2 property3

table: propertyimages
imId adid imorder
1 1 1
2 1 2
3 1 3
4 2 1
5 2 2
6 3 1
7 3 3

Output I want:
adpropname imorder
property2 3
property3 2

Reply With Quote
  #2  
Old April 27th, 2012, 07:38 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 2,349 swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 7 h 27 m 6 sec
Reputation Power: 390
Code:
select property.adpropname,
       dt.imorder
  from property
  cross
  join (select distinct imorder
          from propertyimages) dt
  left
  join propertyimages
    on dt.imorder = propertyimages.imorder
   and property.adId = propertyimages.adid
 where propertyimages.imorder is null

Reply With Quote
  #3  
Old April 27th, 2012, 11:29 AM
dwair dwair is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 53 dwair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 14 m 50 sec
Reputation Power: 8
Many thanks - worked a treat

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Left Join / Join SQL Help need

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