Instead of and use or
Darko Stankovic
Java Developer/Linux Administrator
CasinoVR Inc.
----- Original Message -----
From: Martin Ramsch <m.ramsch@stripped>
To: MySQL mailing list <mysql@stripped>
Sent: Tuesday, October 05, 1999 5:30 AM
Subject: Re: select wanted
> On Tue, 1999-10-05 12:22:13 +0300, Bogdan Paduraru wrote:
> > select from table where day>=limit3 and day<=limit4
> > and month>=limit1 and month<=limit2
> > If limit1=limit2 there is no problem I'll receive the right answer,
> > but if limit1<limit2 and limit3>limit4 my select is not good
> > anymore.
>
> Then you should check for the right order of the limits, and swap them
> if necessary!
>
> If you really, really want it to do within MySQL, you could write:
>
> SELECT FROM table WHERE
> IF(limit3<limit4, day BETWEEN limit3 and limit4
> , day BETWEEN limit4 and limit3)
> AND IF(limit1<limit2, month BETWEEN limit1 AND limit2,
> , month BETWEEN limit2 AND limit1);
>
> Or:
> SELECT FROM table WHERE
> day BETWEEN LEAST(limit3,limit4) AND GREATEST(limit3,limit4)
> AND month BETWEEN LEAST(limit1,limit2) AND GREATEST(limit1,limit2);
>
> But why doing it so complicated?
>
> Just test the limits and swap them _before_ you do the select.
> It's so easily done ...
>
> Regards,
> Martin
> --
> Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/
>
> PGP KeyID=0xE8EF4F75 FiPr=5244 5EF3 B0B1 3826 E4EC 8058 7B31 3AD7
>
> ---------------------------------------------------------------------
> Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
> posting. To request this thread, e-mail mysql-thread15134@stripped
>
> To unsubscribe, send a message to the address shown in the
> List-Unsubscribe header of this message. If you cannot see it,
> e-mail mysql-unsubscribe@stripped instead.
>
>