* DL Neil
[About Christian's problem with joining language specific info.]
>      MIN( FIELD( language, 'no', 'en', 'fr', 'sv' ) )
>

Hi,

I have a similar problem, and have found a workaround that may be useful for
you, Christian. Use an extra left join to find the records you don't want...

# create test tables
create table msg_main (mid int not null,name char(16),primary key(mid));
create table msg_lang (mid int not null,lang char(2) not null,message
text,primary key(mid,lang));

# insert test data
insert into msg_main values (1,'welcome'),(2,'goodbye');
insert into msg_lang values
  (1,'en','Welcome to this test'),
  (1,'se','Välkommen till denna test'),
  (1,'no','Velkommen til denne testen');
insert into msg_lang values
  (2,'se','Hejdå'),
  (2,'no','Adjø');

# select best choice, order of preferred language is: 'en','se','no'
select msg_lang.message
  from msg_main
  left join msg_lang on
    msg_lang.mid=msg_main.mid
  left join msg_lang as unwanted on
    unwanted.mid=msg_main.mid and
    field(unwanted.lang,'en','se','no') <
    field(msg_lang.lang,'en','se','no')
  where name in ('welcome','goodbye') and isnull(unwanted.mid);

I think this will solve your problem. My problem is that I need to do _many_
of these in the same query, and it gets very complex... does anyone know of
an easier way to do this kind of 'dynamic join'?

Roger Baklund,
Mobiliant AS


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to