Hi Michael, ----- Original Message ----- From: "Michael Stassen" Sent: Saturday, March 13, 2004 10:48 AM Subject: Re: BETWEEN
> > Keith wrote: > > > g'day, > > > > i'm looking for a way to do two BETWEEN ranges. Currently I have > > sys.sectorID BETWEEN 1 AND 20 but I want it so that I can search between > > 1 and 20 and also between 30 and 42 but all my efforts net an error and > > the manual doesn't go into a lot of detail. If there's a faster way than > > BETWEEN then 'll take it. > > > > Cheers, > > Keith > > SELECT * FROM sys > WHERE sectorID BETWEEN 1 AND 20 > OR sectorID BETWEEN 30 AND 42; > > If that's slow (the optimizer doesn't like ORs) and you are using at > least mysql 4.0.0, you can change this to The query using 2 BETWEENs with OR is exactly how it should be. It will be fast even in MySQL 3.23. OR is not a problem when the OR parts involve the same index. :-) > SELECT * FROM sys WHERE sectorID BETWEEN 1 AND 20 > UNION > SELECT * FROM sys WHERE sectorID BETWEEN 30 AND 42; > > Michael -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]