Afficher un message
Vieux 19/09/2007, 17h20   #4
Kees Nuyt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: return min between 2 fields

On Tue, 18 Sep 2007 14:12:43 +0200, "Bob Bedford"
<bob@bedford.com> wrote:

>Hi all,
>
>I've to return only 1 field with the minimum value coming from 2 tables:
>
>select min(table1.datetimex) as mindate1, min(table2.datetimex) as mindate2
>from table1 left join table 2 on table1.id = table2.id where table1.id = 123
>or table2.id = 123
>
>In fact I've to check the minimum date if a record has been created in
>table1 or table2.
>
>I've tried min(table1.datetimex, table2.datetimex) as mindate but it doesn't
>work.
>
>How can I do that ?
>
>Also if there is nothing in table1 and something in table2, do I have a
>result ?


Perhaps:
SELECT min(datetimeex)
FROM (
SELECT id,datetimexe FROM table1
UNION
SELECT id,datetimexe FROM table2
) WHERE id = 123;

?

>Thanks for ing
>
>Bob

--
( Kees
)
c[_] Truck Pulls: for people who cannot understand the WWF (#371)
  Réponse avec citation
 
Page generated in 0,05524 seconds with 9 queries