Solved

min(timestamp) in select statement return null

Posted on 2006-07-01
1
1,206 Views
Last Modified: 2008-02-01
I am selecting date type data in following manner. Why it is returning null while condition became falls.

select min(timestamp) from admassist.sye_error_log where SQL_ERRM is not null and sql_code not like '%20003%' ;
If I am using baove statement, it returns 1 null rows.
But if I am wrintting following, it's not selecting anything.
select timestamp from admassist.sye_error_log where SQL_ERRM is not null and sql_code not like '%20003%'


why select with min() funciton return 1 raws that's balnk. I am not expecting any raw to return.

Thank you
~Keyur
0
Comment
Question by:Keyurkumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 23

Accepted Solution

by:
paquicuba earned 500 total points
ID: 17024854
As soon as you use aggregate functions in your SQL, you must be aware that empty sets might come into play. The example below shows how aggregate functions react to empty sets. Apparently, COUNT returns zero whereas AVG, SUM, MAX, and MIN return null. This behavior does make a certain amount of sense. If you have no values to count, it's fair to say that you have zero values, whereas you can't really come up with, say, a maximum value without at least one value from which to choose. We can make a reasonable argument that SUM should return zero instead of null, that the sum of no values is zero, but Oracle's implementation of the behavior we describe here is fully compliant with the SQL standard.

SELECT COUNT(EMPNO),AVG(EMPNO),SUM(EMPNO),MAX(EMPNO),MIN(EMPNO)
FROM EMP_M
WHERE 1 = 2;

COUNT(EMPNO)           AVG(EMPNO)              SUM(EMPNO)        MAX(EMPNO)          MIN(EMPNO)
________________     _____________      _____________     _____________     _____________
0



Try:

select timestamp from admassist.sye_error_log where timestamp = (
select min(timestamp) from admassist.sye_error_log where SQL_ERRM is not null and sql_code not like '%20003%') ;
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question