Yohanne Posted August 10, 2016 Share Posted August 10, 2016 (edited) Hi Coders, how to union two table width different field name and get max id. Edited August 10, 2016 by Yohanne Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 10, 2016 Share Posted August 10, 2016 First off: Why do you have those two tables? Unless you've omitted fields, they're structurally identical and should be a single table. As to your question: The union of the two tables will use the column names of the first table. So it behaves as if everything was stored in TABLE1 and can be used as a subselect for a MAX() query. Quote Link to comment Share on other sites More sharing options...
Yohanne Posted August 10, 2016 Author Share Posted August 10, 2016 (edited) i need to union that table because i have two form with different views and i need to identify witch max id to add 1. may result should be.. depend to a user login result : 6 - - - -> FVCR Edited August 10, 2016 by Yohanne Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 10, 2016 Share Posted August 10, 2016 (edited) I have no idea what you're saying, but I am pretty sure everything you are doing is wrong. Anytime I have seen an OP/Noob using UNION their database is wrong. I am also confident this is an XY Problem. http://xyproblem.info/ The XY problem is asking about your attempted solution rather than your actual problem. This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help. Edited August 10, 2016 by benanamen Quote Link to comment Share on other sites More sharing options...
Yohanne Posted August 10, 2016 Author Share Posted August 10, 2016 okay.. just i need is to identify the max number of field1 and field3. and don't mind where. hope it is clear. and, sorry if i cannot explain well, im not good enough in English. very sorry and i hope u can help me guys. Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 10, 2016 Share Posted August 10, 2016 (edited) Forget the problem you think you need to solve. What exactly do you have going on overall? Your DB column names and data give no indication what is going on there. You say you have two forms with "different views" whatever that is. No one is going to be able to help you based on the non information you have provided. Edited August 10, 2016 by benanamen Quote Link to comment Share on other sites More sharing options...
Solution Yohanne Posted August 10, 2016 Author Solution Share Posted August 10, 2016 thanks guys, to do it in my self finaly solve.. "SELECT MAX(sr_no) AS maxsr, request_to FROM (SELECT sr_generate.srno AS sr_no,sr_generate.sr_branch_code AS request_to FROM sr_generate UNION ALL SELECT smr_request_compile.sr_no, smr_request_compile.request_to FROM smr_request_compile) AS subTable WHERE request_to = '$branch_code'"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.