Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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 28th, 2003, 08:33 AM
SothaSil SothaSil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 5 SothaSil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Excluding rows from a select depending on other table

Hi all,

This is my first posting here.. I tried to read all the docs, and find out what I needed myself, but I guess I can't figure it out. Would anyone be willing to shed some light on this?

I've got a DB with several tables in it, meant for an application where users of a certain community can help translate the site in their native language.

Strings:
id1, string1, string2, project, is_dual
(ID: The ID, String1 is a string, String2 is another string that's supposed to go together with String1 (For translating things like a FAQ it's easier to have the question and answer together, in my reasoning), project is the project this string is part of (the entire translation effort is split into several subprojects), is_dual indicates if the string2 field should be looked at).

Strings_translated:
id2, string_id, string1_trans, string2_trans, language, trans_by
(ID is the ID, string_id is strings.id, the _trans fields are translations of the related fields in Strings, language is an INT indicating which language the translation is in, trans_by is the user ID)

(some other tables for Language, Project and Users, which as are just ID-Name tables)

My problem is that I want to do a SELECT on all Strings that do not have a Translation yet. Without a subquery. I think I got the subquery version, but I need this to run on a server running MySQL 3.x, and perhaps other DB's as well.

Code:
SELECT * FROM strings WHERE id1 NOT IN (SELECT id2 FROM strings_translated) AND project = $project


Would anyone be willing to help me by converting this to a join? I tried it myself, and either I got all results, or no results at all... If you're willing to help me, please also explain what your code does, so I can learn from it

Thank you for your time,

Sotha Sil

Reply With Quote
  #2  
Old December 30th, 2003, 07:55 PM
vanekl vanekl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 229 vanekl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
SELECT s.*
FROM strings s INNER JOIN strings_translated t ON s.id1 = t.id2
WHERE t.id2 IS NULL
AND project = ...

id2 is null only when the record doesn't
exist.

Reply With Quote
  #3  
Old January 5th, 2004, 03:19 AM
SothaSil SothaSil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 5 SothaSil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for looking into this. Unfortunately it doesn't work. The query you gave me seems to always give back 0 results

Any suggestions on what I'm doing wrong?

Edit: After reading up on advanced joins, I figured I needed a Left instead of Inner join. Behold.. it works.

Last edited by SothaSil : January 5th, 2004 at 03:26 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Excluding rows from a select depending on other table


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 2 hosted by Hostway
Stay green...Green IT