Jump to content

[SOLVED] Select MAX returns incorrect value


richrock

Recommended Posts

Hi,

 

In theory, I know why my command isn't returning the required result.  I have a php function that selects a maximum receipt number, then adds +1 to create a new number.  The system is written like this so that numbers can be manually added (another  feature).

 

However, my command:

 

SELECT MAX(receipt_num) FROM receipts;

 

Gives me a result of 89.  The largest number in the column is 1047.  Part of the reasoning is this is a transfer system, and the receipt numbers added afterwards may already exist (hence the manual addition) otherwise going from the top.

 

So why does the command not give me 1047?  It's an INT(4) if that's any help...

 

Rich

Link to comment
Share on other sites

I figured this out.  I had changed the table in the database, and could group by different results to get the right answer. 

 

Regarding auto_increment - I mentioned that there are already a number of pre-existing receipt numbers, many of which are not in the database, hence the need to manually add numbers as clients place new orders, and generate new ones for new clients.  It was an initial thought of mine too.

Link to comment
Share on other sites

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.