Retrieving Data from table based on Date and Time.

Started by VENKTESH GUTTEDARover 11 years ago3 messagesgeneral
Jump to latest
#1VENKTESH GUTTEDAR
venkteshguttedar@gmail.com

Hello,

I have a table in which i have some few fields, in that few, one field
is of date type and second one is of time data type, so now my question is
how can i fetch the data with latest date and time, or the last inserted
value from the PostgreSQL Table.?

--
Regards :
Venktesh Guttedar.

#2Stephen Cook
sclists@gmail.com
In reply to: VENKTESH GUTTEDAR (#1)
Re: Retrieving Data from table based on Date and Time.

On 11/1/2014 2:27 AM, VENKTESH GUTTEDAR wrote:

I have a table in which i have some few fields, in that few, one
field is of date type and second one is of time data type, so now my
question is how can i fetch the data with latest date and time, or the
last inserted value from the PostgreSQL Table.?

SELECT *
FROM mytable
ORDER BY datecolumn DESC,
timecolumn DESC
LIMIT 1;

You might want to put an index on them.

-- Stephen

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3VENKTESH GUTTEDAR
venkteshguttedar@gmail.com
In reply to: Stephen Cook (#2)
Re: Retrieving Data from table based on Date and Time.

Thanks it helped.

On Sat, Nov 1, 2014 at 2:09 PM, Stephen Cook <sclists@gmail.com> wrote:

On 11/1/2014 2:27 AM, VENKTESH GUTTEDAR wrote:

I have a table in which i have some few fields, in that few, one
field is of date type and second one is of time data type, so now my
question is how can i fetch the data with latest date and time, or the last
inserted value from the PostgreSQL Table.?

SELECT *
FROM mytable
ORDER BY datecolumn DESC,
timecolumn DESC
LIMIT 1;

You might want to put an index on them.

-- Stephen

--
Regards :
Venktesh Guttedar.