In my perl script I do the following: my $sth = $dbh->prepare("SELECT MAX(Id) FROM sometable"); my $id = $sth->execute(); print "id: $id\n";
It prints 1 which I guess is the number of rows selected. I was expecting that it would give me the highest id in that table. How can I get that? Thanks for the help. > Petre Agenbag wrote: > > >also makes sense to me to be able to have a get_last_entry() function, > >or a total_rows_in table() (well, I guess you can do that with a select > > > > > > I'm sure I've said it personally a dozen times (and the archives > probably show many other people saying it too); you're not thinking in > SQL; what's wrong with SELECT MAX(ID)? > > How about doing what I always do: > > CREATE TABLE x ( > ID int unsigned not null auto_increment primary key, > MTime timestamp not null, > .... > ); > > Then for the 'most recently affected' row, just do SELECT MAX(MTime) and > for the last inserted row ID, do SELECT MAX(ID). These things are all > accounted for by adding the data to your tables themselves, not by > getting MySQL to track them for you (since if you don't need them, you > can speed up your tables by not having them). > > PS, for cross-join tables, I always use a format like: > > CREATE TABLE x-y ( > xID int unsigned not null, > yID int unsigned not null, > MTime timestamp not null, > ..., > PRIMARY KEY(xID, yID) > ); > > I have a feeling I'm going to put these up on my coding site one of > these days. > > -- > Michael T. Babcock > C.T.O., FibreSpeed Ltd. > http://www.fibrespeed.net/~mbabcock > > > > --------------------------------------------------------------------- > Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > __________________ Aamer Wali Rauf __________________ TC16/123 Jefferson Lab Newport News VA 23606 ph: (757) 269 7346 fax: (757) 269 6273 --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php