Re: mySQL nested select

From: Date: Wed, 05 Jul 2000 19:59:39 +0000
Subject: Re: mySQL nested select
Groups: php.db 
Request: Send a blank email to php-db+get-882@lists.php.net to get a copy of this message
I believe there's no other way for MySQL yet. But do you want to post it on mysql general list instead? Nam.
From: "Lez Lytollis" <lez.lytollis@ccr.ntu.ac.uk> To: "PHP-db list" <php-db@lists.php.net> Subject: [PHP-DB] mySQL nested select Date: Wed, 5 Jul 2000 16:48:53 +0100 Hi, I am trying to pull a set of results from a mySQL db that shows the last set of data a user entered. This works but requires two calls to the db: $last_date_query = "SELECT MAX(user_measurement_date) FROM user_measurements WHERE user_id = '$user_id'"; $last_date = mysql_query($last_date_query) or die(mysql_error()); $tmp_result = mysql_result($last_date,"user_measurement_date"); $query = "SELECT * from user_measurements WHERE user_id = '$user_id' AND user_measurement_date = '$tmp_result' "; Is there a more elegant way to get the data out in one go?: i.e. something like: $query = "SELECT * FROM user_measurements WHERE user_id = '$user_id' AND user_measurement_date = (SELECT MAX(user_measurement_date)
    FROM user_measurements
     WHERE user_id = '$user_id')";
Thanks Lez -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

« previous php.db (#882) next »