Saturday, 15 June 2013

mysql - Join with second table based on first table column -



mysql - Join with second table based on first table column -

hi want bring together registry_ug table sec table based on registry_ug.type.... want avoid unnecessary bring together .

here code

select ug.id , tbl.id registry_ug ug bring together case ug.type when 1 users when 2 group_software end tbl on ug.id = tbl.id ug.id = $uid

it seems ok me error

you have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'case ug.type when 1 users when 2 g' @ line 2 select ug.id , tbl.id registry_ug ug bring together case ug.type when 1 users when 2 group_software end tbl on ug.id = tbl.id ug.id = 55

*and dont want bring together of possible sec tables *

you can't this way. can't utilize case look way. seek instead:

select ug.id, coalesce(u.id, g.id) registry_ug ug left bring together users u on ug.id = u.id , ug.type = 1 left bring together group_software g on ug.id = g.id , ug.type = 2 ug.id = $uid

mysql

No comments:

Post a Comment