mysql - add an extra column while select from two tables -
i have 2 tables me, web , mail. using query fetch data both tables.
preparedstatement ps = con.preparestatement("(select * web name='abc') union (select * mail name='abc')"); resultset rs = ps.executequery(); while(rs.next()){ bw.write(rs3.getstring("name")+"~"+rs3.getstring("age")+"~"+rs3.getstring("profession"); bw.newline(); }
the output this.
+------+------+------------+ | name | age | profession | +------+------+------------+ | abc | 20 | doctor | | abc | 20 | engineer | +------+------+------------+
and in file this
abc~20~doctor abc~20~engineer
but how can add column in result set give me data in format
abc~20~doctor~web abc~20~engineer~mail
select * , 'web' source web name='abc' union select *, 'mail' source mail name ='abc'
Comments
Post a Comment