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



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

Answer / 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

More SQL PLSQL Interview Questions

What is the function that is used to transfer a pl/sql table log to a database table?

1 Answers  


using comand prompt how can import table data and table space with example

2 Answers  


what are the differences between get and post methods in form submitting. Give the case where we can use get and we can use post methods? : Sql dba

1 Answers  


create or replace procedure search_matter(empno varchar2) as sql_stmt varchar2(200); stmt varchar2(200); v_table_name varchar2(200); val_pres number; inp_value varchar2(200); type obj_typ is table of cols.column_name%type index by binary_integer; type all_col is table of varchar2(100) index by binary_integer; typ_obj_typ obj_typ; typ_all_col all_col; begin select object_name bulk collect into typ_obj_typ from user_tables,user_objects where table_name = object_name AND object_type = 'TABLE'; select empno into inp_value from dual; dbms_output.put_line('inp value : '||inp_value); for i in typ_obj_typ.first..typ_obj_typ.last loop v_table_name := NULL; v_table_name := typ_obj_typ(i); dbms_output.put_line(i||':'||typ_obj_typ(i)); dbms_output.put_line('....................'); sql_stmt := 'select column_name from cols where table_name = :1 and data_type in (''CHAR'', ''VARCHAR2'', ''NCHAR'', ''NVARCHAR2'',''NUMBER'')'; EXECUTE IMMEDIATE sql_stmt bulk collect into typ_all_col using typ_obj_typ(i); for inside in typ_all_col.first..typ_all_col.last loop dbms_output.put_line('sql stmt: '||sql_stmt); dbms_output.put_line('column name: '||typ_all_col(inside)||'table name: '||typ_obj_typ(i)); stmt := 'select count(*) from ||typ_obj_typ(i)||'; EXECUTE_IMMEDIATE stmt into val_pres ; if val_pres = 1 then dbms_output.put_line('value present col name: '||typ_all_col(inside)||'table name :'||typ_obj_typ(i)); end if; end loop; dbms_output.put_line('....................'); end loop; exception when others then dbms_output.put_line('sql code '||sqlcode||'Table name: '||v_table_name); dbms_output.put_line('sql message '||sqlerrm); end; Compile-time I am getting below error, Plz help to resolve. LINE/COL ERROR -------- ----------------------------------------------------------------- 47/23 PLS-00103: Encountered the symbol "STMT" when expecting one of the following: := . ( @ % ;

1 Answers  


What mean sql?

1 Answers  


How do I enable sql encryption?

1 Answers  


Which data dictionary views have the information on the triggers that are available in the database?

1 Answers  


I have one table,in that table (1)i have java1.1 version books are 2 and java1.5 version books are 4. (2).Net2.0 books are 3, .Net3.5 books are 2 (3)ABC1.6 books are 4, ABC2.0 books are 3. Now i want output is like Book Count Java 6 .Net 5 ABC 7 For this i need sql query, please help me if anyone how to get this result. Thanks, Seenu

4 Answers   Adea,


Where is pl sql used?

1 Answers  


How do I run a program in pl sql?

1 Answers  


What are the possible values for the boolean data field?

1 Answers  


What is difference sql and mysql?

1 Answers  


Categories