sql - MySQL CASE when SELECT -


i have following query:

select case when `def_spell`.`type` = 0 `spells_damage`.*              when `def_spell`.`type` = 1 `spells_weaken`.*        end  `def_spell`  left join `spells_damage` on `def_spell`.`id` = `spells_damage`.`spell_id`  left join `spells_weaken` on `def_spell`.`id` = `spells_weaken`.`spell_id`  `def_spell`.`id` = 1; 

hopefully makes sense... i'm trying select spells_damage providing type 0 , spells_weaken providing type 1.

i'd select def_spell regardless.

can please fix query? i've never used cases before , not sure how to.

you can't use case choose between output of 2 tables that.

unfortunately, that's easy bit; working out (a) you're trying , (b) achieving equivalent result going take little longer.

it easier if gave information columns in spells_weaken , spells_damage table. presumably, there differences; otherwise, you'd have single table. indeed, single spells table might still better design.

let's put doubts aside. assuming spells_weaken , spells_damage tables union-compatible, can use union achieve result:

select s.*, d.*   def_spell s   left join spells_damage d on s.id = d.spell_id  s.type = 0    , s.id = 1 union select s.*, w.*   def_spell s   left join spells_weaken w on s.id = w.spell_id   s.type = 1    , s.id = 1; 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -