[PHP] Get highest value of key most efficiently
Hi, SQL newbie... What is the most efficient way to get the highest value of a key value using the odbc_* functions/SQL syntax? E.g. if I have a table with key values 1,2,3...1567 I need the higest value: 1567 so I can create a new record and assign key value 1568. I don't want to read the whole table... Met vriendelijke groet / With kind regards, ICL Nederland B.V. Simon de Kraa e-Applications / Logistic Systems Systems Architect Het Kwadrant 1 Tel. +31 346 598865 Postbus 4000Fax +31 346 562703 3600 KA MAARSSEN The Netherlands mailto:[EMAIL PROTECTED] --- Microsoft Windows 2000 5.00.2195 SP 2, Progress 9.1b, Roundtable 9.1c SCO UnixWare 7.1.1, Progress 9.1b -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Get highest value of key most efficiently
Hi, SELECT MAX(column_name) FROM table_name Though for what youre trying to do its better to use an autoincrementing field. That way the database will automaticly increment the key when you do an insert regards, wieger Kraa de Simon wrote: Hi, SQL newbie... What is the most efficient way to get the highest value of a key value using the odbc_* functions/SQL syntax? E.g. if I have a table with key values 1,2,3...1567 I need the higest value: 1567 so I can create a new record and assign key value 1568. I don't want to read the whole table... Met vriendelijke groet / With kind regards, ICL Nederland B.V. Simon de Kraa e-Applications / Logistic Systems Systems Architect Het Kwadrant 1 Tel. +31 346 598865 Postbus 4000Fax +31 346 562703 3600 KA MAARSSEN The Netherlands mailto:[EMAIL PROTECTED] --- Microsoft Windows 2000 5.00.2195 SP 2, Progress 9.1b, Roundtable 9.1c SCO UnixWare 7.1.1, Progress 9.1b -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Wieger Uffink tel: +31 20 428 6868 fax: +31 20 470 6905 web: http://www.usmedia.nl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Good intro to SQL reference Was: Re: [PHP] Get highest value of key most efficiently
You might also want to reference James Hoffman's excellent Introduction to Structured Query Language (SQL Tutorial) page: http://w3.one.net/~jhoffman/sqltut.htm Aral :) __ ([EMAIL PROTECTED]) New Media Producer, Kismia, Inc. ([EMAIL PROTECTED]) Adj. Prof., American University ¯¯ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]