select * from ( select workid1 workid,workcode1 workcode from 表1 union all select * from 表2 union all select * from 表3 ) where workid=? and workcode =?
楼主的意思 没听明白 不过建议学习下SQL 多表联合查询 试下JOIN
如果只是将3个表的 id code联合(匹配)查询,那上面的union all可以实现 但要取某一表中的其它字段,建议使用join select a.字段1,b.字段1,c.字段1 from table1 a join table2 b on a.workid = b.workid and a.workcode = b.workcode join table3 c on a.workid = c.workid and a.workcode = c.workcode
select workid1 workid,workcode1 workcode from 表1 union all
select * from 表2 union all
select * from 表3 ) where workid=? and workcode =?
但要取某一表中的其它字段,建议使用join
select a.字段1,b.字段1,c.字段1 from table1 a
join table2 b on a.workid = b.workid and a.workcode = b.workcode
join table3 c on a.workid = c.workid and a.workcode = c.workcode