MYSQL: Getting certain data from a cross join depending on condition -
this problem query:
select distinct t.name tname, t.task_group tg, tgs.name tgname tasks t, task_users tu, task_groups tgs (tu.worker = 1 , t.keyid = tu.task , tgs.keyid = t.task_group);
the query works. thing part of clause tgs.keyid = t.task_group filters out results condition not true (which is, of course correct).
how can modify query , still tname when condition not true , in case obtain predefined string tgname?
to give information when condition not true t.task_group allways -1. in case tgname of "n/a".
how can this?
use case...when...else...end
:
select distinct t.name tname, t.task_group tg, case when tgs.keyid = t.task_group tgs.name else 'something else' end tgname tasks t, task_users tu, task_groups tgs (tu.worker = 1 , t.keyid = tu.task);
Comments
Post a Comment