Jump to content

union two table and get max id


Go to solution Solved by Yohanne,

Recommended Posts

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.

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 by Yohanne

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 by benanamen

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 by benanamen
  • Solution

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'";
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.