[thelist] Free Tip about SQL

Chris W. Parker cparker at swatgear.com
Fri Jul 18 11:39:04 CDT 2003


Jay Blanchard <mailto:jay.blanchard at niicommunications.com>
    on Friday, July 18, 2003 9:11 AM said:

> Can't you do (if for instance the id field is named ID)
> 
> SELECT MAX(ID) FROM foo
> 
> ?

If you simply want the highest id number then yes. But if you want the
id of a record you just inserted you'll have to use the WHERE clause.

It's possible that before you turn around and ask the database that
question (your query above) another record has already been added.

I usually do something like:

SELECT id
FROM users
WHERE username = 'chris'
	AND coolfactor = 'infinite'
	AND babemagnet = 'yes';

(we are assuming that) chris, infinite, and yes all came from
information that was passed to a form on a website.


Chris.

p.s. it would be totally dudical if you'd trim your posts


More information about the thelist mailing list