MySQL Help
 
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 ForumsDatabasesMySQL Help

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 December 7th, 2012, 06:54 AM
Eng_A_Moktar Eng_A_Moktar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 75 Eng_A_Moktar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 3 h 26 m 46 sec
Reputation Power: 4
Select rows which have no match in other table?

I have this structure
tbl_site_urls: storing urls of a site
tbl_camp_urls: storing urls of a campaign, after handling these urls
tbl_site_urls
id - site_id - url
1 - 181 - url1
2 - 182 - url2
3 - 189 - url3

tbl_camp_urls
id - camp_id - site_id - url
1 - 5 - 181 - url1


if i want to list the urls need to be handle

select url from tbl_site_urls
join site on tbl_site_urls.site_id = site.id AND site.valid=1

then in a loop operation i insert the handled urls into the tbl_camp_urls

I want to list the urls that which have not handled yet.
it is like a comparison operation.


The results I'm expecting is
2 - 182 - url2
3 - 189 - url3

Reply With Quote
  #2  
Old December 9th, 2012, 03:34 AM
bobert123 bobert123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 55 bobert123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 40 m 30 sec
Reputation Power: 2
there are 2 ways to do this. you should experiment to see which is more efficient with your tables (usually it's the 2nd one)

1.
Quote:
SELECT url FROM tbl_site_urls
WHERE tbl_site_urls.site_id NOT IN (SELECT site.id FROM site)


2.
Quote:
SELECT url FROM tbl_site_urls
LEFT JOIN site ON tbl_site_urls.site_id=site.id WHERE site.id IS NULL

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Select rows which have no match in other 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