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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.