richrock Posted November 3, 2008 Share Posted November 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/131194-solved-select-max-returns-incorrect-value/ Share on other sites More sharing options...
Barand Posted November 3, 2008 Share Posted November 3, 2008 Why don't you make the receipt_number an auto_increment column? Quote Link to comment https://forums.phpfreaks.com/topic/131194-solved-select-max-returns-incorrect-value/#findComment-681385 Share on other sites More sharing options...
richrock Posted November 4, 2008 Author Share Posted November 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/131194-solved-select-max-returns-incorrect-value/#findComment-681898 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.