SunQuest
 
           General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 11th, 2004, 10:17 PM
Decoy Decoy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 28 Decoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Simple join returning odd results

I have a very simple database set up where I use one table to display all the current link categories available, and another to hold the respective links. 'catid' is the primary key for the 'link_cat' table and the foreign key to the 'links' table.

Everything works well, but on an administrative section of the site, I give the owner the ability to add/edit/delete the categories and links. I simply loop through both tables and list all the categories with an 'edit' and 'delete' button next to it and a seperate table for the 'links' table.

This too works well, but I'd like to isolate the categories that exist, but don't have any links associated with them yet, and stray links lying around after the category they were once associated with no longer exist.

LINK_CAT TABLE
---------------
catid <-- pri key
cat_name

LINKS TABLE
-----------
linkid <-- pri key
catid <-- foreign key
link_url
alt

When I use this query, it comes back correct. It returns the link(s) which have an existing catid in the 'link_cat' table
PHP Code:
 SELECT name FROM linkslink_cat
WHERE links
.catid link_cat.catid

However if I try this one, it returns everything twice, PLUS it also returns the link that has a matching catid in the 'link_cat' table??
PHP Code:
 SELECT name FROM linkslink_cat
WHERE links
.catid != link_cat.catid

The only difference in them is the '!' in front of the '=' on the second query. I'm not even sure if I'm going at this the right way. I appreciate all suggestions. (I uploaded a zip file of the tables if anyone wants to look)

Thanks
Attached Files
File Type: zip sample.zip (610 Bytes, 301 views)

Reply With Quote
  #2  
Old March 11th, 2004, 11:21 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Use and LEFT JOIN - and check for NULL in the link field key field.... I believe MadCow posted the answer for this about a week ago...
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old March 11th, 2004, 11:53 PM
Decoy Decoy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 28 Decoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I searched all of MadCowDzz's recent post and didn't see a thread similar to mine. Would you be kind enough to show me an example of what you posted?

Thanks

Reply With Quote
  #4  
Old March 12th, 2004, 09:04 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8

Reply With Quote
  #5  
Old March 12th, 2004, 01:12 PM
Decoy Decoy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 28 Decoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz

No, stumpy mistakenly thought you addressed my post about a week ago, I then looked for your recent posts but didn't see any similar to mine . Would you take a look at my original post and tell me what you think?

Robin

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Simple join returning odd results


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway