Thread: SQL question

SQL question

From
kevin kempter
Date:
Hi List;

I have a table that has 3 date columns :

create table xyz (
xyz_id integer,
date1   timestamp,
date2   timestamp,
date3   timestamp
)


I want to select in a query the xyz_id and the max date column for
each row
something like :
create table temp2 as select xyz_id (max date?) where ...

Is this - the (max date?) part a case scenario or is there a better,
more efficient method ?

Thanks in advance


Re: SQL question

From
"Adam Rich"
Date:
> I have a table that has 3 date columns :
>
> create table xyz (
> xyz_id integer,
> date1   timestamp,
> date2   timestamp,
> date3   timestamp
> )
>
>
> I want to select in a query the xyz_id and the max date column for
> each row
> something like :
> create table temp2 as select xyz_id (max date?) where ...

Is this what you want?

Select xyz_id, greatest(date1,date2,date3) from xyz where...

http://www.postgresql.org/docs/8.3/interactive/functions-conditional.html#AE
N14508