adspace


Table 1: col1 Timestamp
----------------
01-mar-2012 11:12:46

Table 2: col2 Timestamp
--------------------
01-mar-2012 11:12:10
01-mar-2012 11:11:23

Write a query to display a row with table2 col2 value less
than tabl1 col1 value. Maximum timestamp value previous to
table1 col1 value.

Display a result as:

Col1 col2
----- -----
01-mar-2012 11:12:46 01-mar-2012 11:12:10

Answer Posted / Subhash Kumar Maurya

WITH latest AS ( SELECT MAX(col1) as max_date FROM your_table1 ), older AS ( SELECT * FROM your_table2 WHERE col2 < (SELECT max_date FROM latest) ORDER BY col2 DESC LIMIT 1 ) SELECT col2 FROM older;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the current version of postgresql?

1178


Can we rollback truncate?

1074


How do I remove duplicates in two columns?

1187


how to use regular expression in pattern match conditions? : Sql dba

1113


what is dbms? : Sql dba

1061


Is primary key clustered index?

1019


how to start mysql server? : Sql dba

1267


how many tables will create when we create table, what are they? : Sql dba

1144


Do we need to rebuild index after truncate?

1138


what are the advantages of sql ? : Sql dba

1142


Is primary key always clustered index?

1095


What is your daily office routine?

2346


Hi am new to PLSQL & facing problems in writing code like in SP, Functions, so any one having some SP coding with in depth explanation please share with me my Email ID suvarnaatsuvarna@rediffmail.com Or taking tanning on this please do contact me

2091


Can delete statement be rollbacked?

1054


define sql insert statement ? : Sql dba

1098