473,473 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP/MySQL: using MIN() on an empty set of rows -> query error

I'm using: "select min(objid) from table_name where objid > $objid"
to select the next row in a sequence where there may be gaps. It
works fine unless the where clause results in an empty set.

From the command line, a value is *always* returned, which is NULL
when the set of rows selected by the where clause is empty. I wasn't
sure what I expected mysql_query to return. I didn't expect a FALSE
result, since the query is syntactically valid, but that's what I got.

Surely this is a bug? An empty result set would seem to be the correct
response, not a query error.

jim
--
Jim Hatfield
Jul 17 '05 #1
2 2909
On Tue, 31 Aug 2004 16:22:26 +0100, Jim Hatfield <ji**********@insignia.com> wrote:

Surely this is a bug? An empty result set would seem to be the correct
response, not a query error.


Or even one row with an empty string as the returned value, which
is what I got after I played around with it for a while. I must have
been doing something else wrong...
--
Jim Hatfield
Jul 17 '05 #2
.oO(Jim Hatfield)
I'm using: "select min(objid) from table_name where objid > $objid"
to select the next row in a sequence where there may be gaps. It
works fine unless the where clause results in an empty set.

From the command line, a value is *always* returned, which is NULL
when the set of rows selected by the where clause is empty. I wasn't
sure what I expected mysql_query to return.
A resource ID.
I didn't expect a FALSE
result, since the query is syntactically valid, but that's what I got.
A return value FALSE indicates an error. Check mysql_error().

mysql_query() always returns a resource ID if the query was successful,
even if the result set is empty or contains NULL. What versions of PHP
and MySQL do you use?
Surely this is a bug? An empty result set would seem to be the correct
response, not a query error.


In this case a result set with one value NULL would be correct (there's
no min-value in an empty set).

Micha
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Don Crossman | last post by:
Assume a MYSQL table, foo. One column, bar datetime. Two rows: 2004-01-01 08:00:00 2004-02-01 08:00:00 select * from foo where extract(day from bar)=1; 2 rows in set...
1
by: Marcus | last post by:
Hello, quick question about MySQL storing NULL values... Say I have a textbox called $_POST and a variable $var. if(empty($_POST)) $var = NULL; else $var = $_POST; Disregarding...
9
by: Sandy | last post by:
I am trying to do the following: EXEC SQL UPDATE MY TABLE SET COL1 = :newValue WHERE COL1 = 0 AND ROWNUM = 1 ORDER BY COL2; (index on COL1, COL2)
3
by: hshen | last post by:
Hi All, I have encountered a weird behavoir of embedded MySQL. Through a simple program I made (in Delphi 6), I can insert rows to a table through embedded MySQL and I can retrieve the rows from...
115
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i...
5
by: asadikhan | last post by:
Hi, I am trying to configure my asp.net application to work with MySQL using Connector/NET and I wish to use connection pooling. What is the best way to do this? This is what I have so far: ...
1
by: lorenzdominic_ | last post by:
Hello What is the best way to test if a recordset is empty using PHP and MySQL? Regards Dominic
7
by: greywire | last post by:
So I need to load lots of data into my database. So I discover LOAD DATA INFILE. Great! This little gem loads my CSV in blazing times (compared to parsing the file and doing INSERT for each...
4
by: webandwe | last post by:
Hi, I have a database with a row called "time". I need to somehow add up all the time rows and then echo out the total. How do I do it? Example MySQL -----------
1
by: toretto | last post by:
Hello, I have a script php that I use on my website to permit visitors to send me some email with some data, this is the html table code: <table width="730" border="0" cellpadding="0"...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.