Search Postgresql Archives

Re: Between with a list of ranges possible ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/29/2015 10:41 AM, John R Pierce wrote:
On 5/29/2015 9:32 AM, Arup Rakshit wrote:
Can I do the below 3 queries in a single query  ?

select * from table where number * 3 between start_value1 and end_value2; select * from table where number * 3 between start_value2 and end_value2; select * from table where number * 3 between start_value3 and end_value3;

select * from table where (number * 3 between start_value1 and end_value2) OR
            (number * 3  between start_value2 and end_value2) OR
            (number * 3  between start_value3 and end_value3);

oh, do note, this won't be /exactly/ the same if the ranges overlap. your first would return the overlapping rows for each query, while the OR version will just return one of each row that is in any of the ranges.

--
john r pierce, recycling bits in santa cruz



--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux