* Bjoern Wuest 
> I work on this problem for three days now and could not find any 
> tip in any manual, book, tutorial or search engine.
> 
> I have the following problem:
> 
> Table1 'pl':
> +---+---+
> | p | o |
> +---+---+
> | 1 | 1 |
> | 2 | 1 |
> | 3 | 2 |
> +---+---+
> 
> Table2 'ln':
> +---+------+---+
> | p |   l  | v |
> +---+------+---+
> | 1 | 'de' | 9 |
> | 1 | 'en' | 8 |
> | 1 | null | 7 |
> | 2 | 'en' | 6 |
> | 2 | null | 5 |
> | 3 | null | 4 |
> +---+------+---+
> 
> Now my problem: how to write a statement to select all 'p' and 
> 'v' from 'pl' and 'ln' where 'o=1' and 'l=de' or 'l=null if 
> l=de is unavailable'. 

Maybe something like this could work:

SELECT pl.p,IF(ISNULL(de.v),nu.v,de.v) AS v
  FROM pl 
  LEFT JOIN ln AS de ON
    de.p=pl.id AND de.l = 'de'
  LEFT JOIN ln AS nu ON
    nu.p=pl.id AND nu.l IS NULL  
  WHERE o = 1

-- 
Roger

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to