Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there integer ranges for Where Clause?

Tags:

sql

oracle

I need to check that result of expression in where clause is in range of Integers.

something lke this:

select * from table where (col1 / col2 ) in (1..8). 

With (1..8) representing a range of integers.

I mean that it must be integer, not float. So that I cant use between 1 and 8, because 1.2 will be correct.

like image 351
zmische Avatar asked Jul 16 '09 13:07

zmische


People also ask

Is there any limitation in adding a number of conditions in a WHERE clause?

The maximum number of clauses in a WHERE clause is 40.

WHERE clause pass multiple values?

The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.

Which conditions can we use with WHERE clause?

The SQL WHERE clause is used to specify a condition while fetching the data from a single table or by joining with multiple tables. If the given condition is satisfied, then only it returns a specific value from the table. You should use the WHERE clause to filter the records and fetching only the necessary records.


2 Answers

You can of course do this:

select * from table where (col1 / col2 ) in (1,2,3,4,5,6,7,8);

or

select * from table where (col1 / col2 ) between 1 and 8
and mod (col1 , col2 ) = 0;
like image 200
Tony Andrews Avatar answered Oct 20 '22 09:10

Tony Andrews


How about

select * 
from table
where (col1 / col2 ) BETWEEN 1 AND 8
  and (col1 / col2 ) = FLOOR(col1 / col2 )

This simply checks if the fraction is in the interval, and integer.

like image 36
Martin Bøgelund Avatar answered Oct 20 '22 09:10

Martin Bøgelund