MYSQL: Query with a two cases allways showing both cases -


the query in question this:

select distinct        t.name tname,        t.keyid tkeyid,       t.task_group ttg,       case when (tgs.keyid = t.task_group , p.keyid = tgs.proyect) p.name else 'n/a' end pname       tasks t, task_users tu, task_groups tgs, proyects p       (tu.worker = 1 , t.keyid = tu.task) order tkeyid asc; 

the query should show me p.name registered in proyects table when condition of case met , n/a otherwise. there serveral entries in tasks such t.task_group = -1 condition not met. these shown correctly in results.

however if t.task_group positive number (an actual reference task_group) query shows me 2 results so:

+----------------------+--------+------+-------------------------------+ | tname                | tkeyid | ttg  | pname                         | +----------------------+--------+------+-------------------------------+ | sensor de frecuencia |    170 |   11 | biblioteca_perifericos_01     | | sensor de frecuencia |    170 |   11 | n/a                           | 

why doing , how can correct it?

ok, i've kept @ , found query wanted. i'm leaving here might similar problem.

select distinct        t.name tname,        t.keyid tkeyid,       t.task_group ttg,       case when (t.task_group != -1) (select p.name proyects p, task_groups tg tg.keyid = t.task_group , tg.proyect = p.keyid) else 'n/a' end pname       tasks t, task_users tu       (tu.worker = 1 , t.keyid = tu.task) order tkeyid asc; 

this simpler (conceptually, @ least) since query datum want when condition t.task_group = -1 true.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -