
May 11th, 2012, 01:42 PM
|
|
Contributing User
|
|
Join Date: Aug 2011
Posts: 51
Time spent in forums: 10 h 8 m 48 sec
Reputation Power: 2
|
|
|
Finding Max Value in a Row
I've encountered this problem a few times in my sad and short SQL career. I have a table with rows  and I know there are 298 records in the field labeled PRIMARY KEY:
Code:
SELECT COUNT(*) AS total_usrs
FROM users;
This tells me there are '298' records but the values are not configured in a sequence so in order for me to enter a new row of data into the users table, I need to find out what the maximum value listed in the users_id field. If I look up the users_id for the row # 298 (not sure how to do that in ANSI SQL either  ) but that could give me a value of 2000012 & there's no guarantee that the last row in the field is using the maximum value since ORDER BY isn't really functional when I use COUNT(*). Can someone please tell me the easiest way to locate the maximum value used on a particular column / field using a simple SQL statement? I search Google and some manual references and
|