List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:October 17 2000 7:14pm
Subject:Re: implementing logical OR in WHERE
View as plain text  
In the last episode (Oct 17), Stas Bekman said:
> When I execute 
> SELECT ... WHERE lang='en' OR lang='fr';
> 
> I get *all* the matching records. 
> 
> What I want is to match only records where lang='en' and if it's not
> there than to match the records where lang='fr'.

So you've got a table like:

docID | lang | transID | body
------+------+---------+------
    1 | en   | 1       | "Text in english"
    1 | fr   | 2       | "Text en francais"
    2 | fr   | 3       | "Text en francais"
    3 | en   | 4       | "Text in english"

And you want a french-speaking user to get translation #2 in preference to
translation #1 when they request document #1?

You'll probably have to do a 2-stage query.  Select the docID, transID
and lang for all the documents you're interested in, then figure out
which records from the database you actually want and pull them by
transID another query.  Create a 3-field index on docID, lang, and
transID for faster lookups.

With subqueries you could probably handle the whole thing in one query,
but MySQL doesn't have them.


-- 
	Dan Nelson
	dnelson@stripped
Thread
implementing logical OR in WHEREStas Bekman17 Oct
  • RE: implementing logical OR in WHERECarsten H. Pedersen17 Oct
    • RE: implementing logical OR in WHEREStas Bekman17 Oct
  • Re: implementing logical OR in WHEREDan Nelson17 Oct
    • Re: implementing logical OR in WHEREStas Bekman17 Oct
  • Re: implementing logical OR in WHEREBob Hall18 Oct
    • Re: implementing logical OR in WHEREBenjamin Pflugmann19 Oct
  • Re: implementing logical OR in WHEREJan Dvorak21 Oct
    • Re: implementing logical OR in WHEREStas Bekman26 Oct
Re: implementing logical OR in WHEREBob Hall21 Oct