PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > return min between 2 fields
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
return min between 2 fields

Réponse
 
LinkBack Outils de la discussion
Vieux 18/09/2007, 13h12   #1
Bob Bedford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut return min between 2 fields

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 ?

Thanks for ing

Bob


  Réponse avec citation
Vieux 18/09/2007, 14h09   #2
ZeldorBlat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: return min between 2 fields

On Sep 18, 8:12 am, "Bob Bedford" <b...@bedford.com> wrote:
>
> Also if there is nothing in table1 and something in table2, do I have a
> result ?
>


Suppose you have nothing in your left hand and nothing in your right
hand. Which of the two nothings is smaller?

  Réponse avec citation
Vieux 18/09/2007, 14h24   #3
Bob Bedford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: return min between 2 fields

>> Also if there is nothing in table1 and something in table2, do I have a
>> result ?
>>

>
> Suppose you have nothing in your left hand and nothing in your right
> hand. Which of the two nothings is smaller?


my question was: nothing in my left and and something in my right hand....in
a query.


  Réponse avec citation
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
Vieux 19/09/2007, 21h47   #5
Kees Nuyt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: return min between 2 fields

On Wed, 19 Sep 2007 18:20:53 +0200, Kees Nuyt
<k.nuyt@nospam.demon.nl> wrote:

>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;
>
>?


Or (probably more efficient):
SELECT min(datetimeex)
FROM (
SELECT id,datetimexe FROM table1 WHERE id = 123
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
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h36.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14344 seconds with 13 queries