Questions tagged [in-operator]

expr IN (value,...) --> Returns 1 if expr is equal to any of the values in the IN list, else returns 0.

expr IN (value,...)

Returns 1 if expr is equal to any of the values in the IN list, else returns 0. If all values are constants, they are evaluated according to the type of expr and sorted.

For Example:

SELECT 2 IN (0,3,5,7);
        -> 0
SELECT 'wefwf' IN ('wee','wefwf','weg');
        -> 1
153 questions
279
votes
3 answers

Override Python's 'in' operator?

If I am creating my own class in Python, what function should I define so as to allow the use of the in operator, e.g. class MyClass(object): ... m = MyClass() if 54 in m: ...
astrofrog
  • 32,883
  • 32
  • 90
  • 131
110
votes
15 answers

Is there a C# IN operator?

In SQL, you can use the following syntax: SELECT * FROM MY_TABLE WHERE VALUE_1 IN (1, 2, 3) Is there an equivalent in C#? The IDE seems to recognise "in" as a keyword, but I don't seem to be able to find any information on it. So, is it possible…
Paul Michaels
  • 16,185
  • 43
  • 146
  • 269
101
votes
6 answers

Performance differences between equal (=) and IN with one literal value

How does SQL engines differ when we use equal sign and IN operator have same value? Does execution time changes? 1st one using equality check operator WHERE column_value = 'All' 2nd one using IN operator and single value WHERE column_value IN…
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
55
votes
6 answers

Why does javascript's "in" operator return true when testing if 0 exists in an array that doesn't contain 0?

Why does the "in" operator in Javascript return true when testing if "0" exists in array, even when the array doesn't appear to contain "0"? For example, this returns true, and makes sense: var x = [1,2]; 1 in x; // true This returns false, and…
Mariano Peterson
  • 774
  • 1
  • 6
  • 7
48
votes
13 answers

How to use php array with sql IN operator?

I have and array with two values and I want to use it with sql IN operator in select query. Here is the structure of my table id comp_id 1 2 2 3 3 1 I have an array $arr which have two values Array ( [0] => 1 [1] => 2 ) I want to fetch the…
Ahmad
  • 2,099
  • 10
  • 42
  • 79
33
votes
5 answers

Java in operator

For the one millionth time, I would have liked to use an IN operator in Java, similar to the IN operator in SQL. It could just be implemented as compiler syntactic sugar. So this if (value in (a, b, c)) { } else if (value in (d, e)) { } ...would…
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
29
votes
8 answers

Imitating the "IN" Operator

How can one achieve: if X in (1,2,3) then instead of: if x=1 or x=2 or x=3 then In other words, how can one best imitate the IN operator in VBA for excel?
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
25
votes
3 answers

T-SQL: Where xxx IN temporary table

I have a temp table and want to check in a where clause wether a certain id/string is contained in the temp table. Select... WHERE MyId IN MyTempTable I get a general error in MS SQL Management studio. is the "In" operator not suited for temp…
Elisabeth
  • 20,496
  • 52
  • 200
  • 321
20
votes
2 answers

In Python, how is the in operator implemented to work? Does it use the next() method of the iterators?

In Python, it is known that in checks for membership in iterators (lists, dictionaries, etc) and looks for substrings in strings. My question is regarding how in is implemented to achieve all of the following: 1) test for membership, 2) test for…
bp14
  • 545
  • 5
  • 10
18
votes
3 answers

How does the Groovy in operator work?

The Groovy "in" operator seems to mean different things in different cases. Sometimes x in y means y.contains(x) and sometimes it seems to call y.isCase(x). How does Groovy know which one to call? Is there a particular class or set of classes that…
ataylor
  • 64,891
  • 24
  • 161
  • 189
15
votes
1 answer

MySQL in-operator must match all values?

I've made my own forum. When doing a search I want to find any threads where two (or more) specific users have participated. I came up with this: SELECT * FROM table1 INNER JOIN table2 ON table1.threadid=table2.threadid WHERE…
adp
  • 226
  • 2
  • 9
15
votes
2 answers

Postgresql IN operator Performance: List vs Subquery

For a list of ~700 ids the query performance is over 20x slower than passing a subquery that returns those 700 ids. It should be the opposite. e.g. (first query takes under 400ms, the later 9600 ms) select date_trunc('month', day) as month,…
14
votes
2 answers

Using IN clause in a native sql query

We are trying to dynamically generate an IN clause for a native sql query to return a JPA entity. Hibernate is our JPA provider. Our code looks something like this. @NamedQuery( name="fooQuery", queryString="select f from Foo f where…
VerrDon Mason
14
votes
1 answer

Using IN clause in a native sql query with Hibernate 3.2.2

In a fashion similar to the question found here: Using IN clause in a native sql query; I am attempting to make use of an IN() clause by way of a native SQL query in Hibernate. While the author in the other question was able to use JPA, I am not. In…
carlsz
  • 2,224
  • 3
  • 18
  • 16
13
votes
3 answers

Python "in" operator speed

Is the in operator's speed in python proportional to the length of the iterable? So, len(x) #10 if(a in x): #lets say this takes time A pass len(y) #10000 if(a in y): #lets say this takes time B pass Is A > B?
Anshu Dwibhashi
  • 4,617
  • 3
  • 28
  • 59
1
2 3
10 11