Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT MAX(col) .. WHERE produces the wrong result

Status
Not open for further replies.

albatross68

Programmer
Sep 19, 2008
3
GR
I have a table with the following fields (among others):
Code:
tid SERIAL
ext_id INTEGER
The idea is that a number of records may exist in this table for a given ext_id, but tid is unique and increases with each new record

My goal is to locate the most recent record for a given ext_id (say 12345). So I tried:
Code:
SELECT MAX(tid) INTO last_tid
FROM table
WHERE ext_id = 12345
This does not work as expected when no record exists in the table for ext_id = 12345. In this case -as far as I can tell- the result is the maximum tid in the table (i.e. as if there was no WHERE clause in my query).

Also if the table is empty, I get a runtime error -201.

Please note that the installation uses an old version of Informix (7.x).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top