因为表结构是用那边设计的,一个表的字段关联了2个表,用一个字段控制,今天因为业务要查询所有,这样就出问题了。
具体解决方法用到了union。
union的作用是将2个子查询和到一起。
select g.id,g.`name`,s.schoolname from groups g,schools s where g.target_id=s.id and g.type!='LIST001003'
union
select g.id,g.`name`,o.`name` orgname from groups g,default_orgs o where g.target_id=o.id and g.type='LIST001003'