Home » SQL & PL/SQL » SQL & PL/SQL » new in sql need help with date datatype and java (ORACLE XE, ubuntu 7.10, java)
icon8.gif  new in sql need help with date datatype and java [message #297254] Wed, 30 January 2008 20:14 Go to next message
Messages: 1
Registered: January 2008
Junior Member
I'm doing all this queries from a simply java application based on jdk5. I have a basic table, and i'm completly new at SQL so I'm sorry if this is a really easy question but there it goes.
My table has 2 columns, one with dates and another one with numbers. What i want to do is to select the most recent value from the numbers column, in oder words, select the value from the numbers column that has the corresponding maximum date.

I've been trying everything to get this done, but it just doesn't. One of the first things i try was just simply consulting the table for the max value in the date column, so with this one in a new query selecting the number value that corresponds to that one.

(1) select max(DATE) from TABLE as MAXDATE;
(2) select NUMBER from TABLE where DATE=MAXDATE;

It looks simple but the main problem is that when i recover the max(DATE), the string has a weird format, so it can't compare it with the date datatype. I've tried using the to_date() function when comparing but it doesn't work, i've try every single parameter.
What i've seen is that to compare dates i have to use a string similar to 'DD-MON-YY' and the String that i get by doing the first query has the format 'YYYY-MM-DD hh:mm:ss.m'

Please any help, i'm dying here.
Re: new in sql need help with date datatype and java [message #297259 is a reply to message #297254] Wed, 30 January 2008 21:57 Go to previous message
Messages: 247
Registered: September 2006
Location: New Delhi
Senior Member
select max(date_column) as maxdate from table_name;

select column_name from table where date_column in (select max(date_column) as maxdate from table_name);

also, post your problem in prescribed format by forum.

Previous Topic: NUMTODSINTERVAL bring back same dates
Next Topic: Need to skip unique constraint
Goto Forum:

Current Time: Fri Jul 21 08:05:55 CDT 2017

Total time taken to generate the page: 0.09776 seconds