Colin Guthrie wrote: > Mark wrote: >>> select user_id from t_users where user_id = (select max(user_id) from >>> t_users) >>> >> >> It should be noted that that is the absolute 100% WRONG way to do it. If >> your site has any concurrency, you will almost certainly get the wrong >> user. > > I agree 100% that it is 100% wrong, but just to point out something > blindingly obvious: it is also incredibly inefficient at being wrong!! > > The sub-select selects the maximum user_id in the table. Fair enough. > This user_id is then fed into a statement that just returns that value > via a pointless lookup. > > SELECT user_id from t_users WHERE user_id = 42; > > Hmmmmm I wonder what user_id I'll get from that select.... > Yea, I didn't see that little bit. My eyes saw max(user_id) and thought, man, these guys should go to school or buy a book. I'm not talking anything serious, just basic computer science 101. I often wonder, looking at these questions, what is the state of the web? If any notable percent of it is written with this much basic ignorance of computing, then the web is basically broken. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php