List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:October 5 1999 9:30am
Subject:Re: select wanted
View as plain text  
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
Thread
select wantedbpaduraru5 Oct
  • Re: select wantedMartin Ramsch5 Oct
    • Re: select wantedbpaduraru5 Oct
      • Re: select wantedBob Kline5 Oct
      • Re: select wantedMartin Ramsch5 Oct
        • Re: select wantedMichael Widenius7 Oct
  • Re: select wantedBob Kline5 Oct
  • Re: select wanteddstankovic5 Oct
  • select into outfiledstankovic5 Oct
    • Re: select into outfilesinisa5 Oct