MySQL Query Help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Number1SuperGuy
Forum Newbie
Posts: 10
Joined: Thu Jun 17, 2010 11:21 am

MySQL Query Help

Post by Number1SuperGuy »

Hey everyone, I'm getting the following error when running a SELECT query:
Warning: mysql_query() [function.mysql-query]: Unable to save result set in /home/ehacsv/public_html/data.php on line 202
:banghead: :banghead: :banghead: :banghead:

It's a pretty complicated query, but it looks right to me. Can any of you spot the error? If it helps, line 202 is the last line in the following code:

Code: Select all

$selectquery = mysql_query (
	"SELECT data_id, data_timestamp, data_gas, data_electric, data_water FROM data WHERE (
		data_reading_id = (
			SELECT reading_id FROM readings WHERE (
				reading_month = '$reading_month_prev' AND reading_year = '$reading_year_prev'
			)
		) AND data_property_id = '$property_id' AND data_timestamp = (
			SELECT MAX(
				data_timestamp
			) FROM data WHERE (
				data_reading_id = (
					SELECT reading_id FROM readings WHERE (
						reading_month = '$reading_month_prev' AND reading_year = '$reading_year_prev'
					)
				) AND data_property_id = '$property_id'
			)
		)
	)"
);
Number1SuperGuy
Forum Newbie
Posts: 10
Joined: Thu Jun 17, 2010 11:21 am

Re: MySQL Query Help

Post by Number1SuperGuy »

If anyone's curious I solved the problem. Basically what was happening was those nested select queries were returning multiple results, which was screwing up the whole thing. I tightened up my code a bit and added LIMIT 1 to all of the nested select statements and now it works like a charm.
Post Reply