I have to select rows from the table where col1=max(col1).
Here if the max(col1) is null, i dont get results because NULL cannot be compared as far as i know.
Temporarily i have used COALESCE(COL1,CURRENT_DATE)= COALESCE(MAX(COL1),CURRENT_DATE) to fetch records.
Will this temp solution affect in terms of performance ?
I have also tried creating a volatile table with these coalesce statements then used those columns to filter. Which one is better using ?
Please suggest if there is any other means to acheive.
Scenario:
CREATE VOLATILE TABLE tbl1
( name VARCHAR(10),
dt DATE
)ON COMMIT PRESERVE ROWS;
INSERT INTO tbl1
('mk', NULL);
INSERT INTO tbl1
('jk', NULL)
SEL * FROM tbl1 -- 2 inserted records
SEL * FROM tbl1
WHERE dt=(SEL MAX(dt) FROM tbl1);
--No records
SEL * FROM tbl1
WHERE COALESCE(dt,CURRENT_DATE)=(SEL COALESCE(MAX(dt),CURRENT_DATE) FROM tbl1);
--2 Records from the table
Thanks in advance.
Tags:
Forums: