Questions tagged [in-clause]

The IN clause of a SQL query is a function, generaly used within a WHERE clause, that returns true if a value is in a given set. Use for questions relating to this clause.

The IN clause of a SQL query is a function, generaly used within a WHERE clause, that returns true if a value is in a given set. For example,

SELECT *
FROM foo
WHERE bar IN(24, 37, 82);

will only return rows from foo if bar is either 24, 37, or 82.


More examples:

SELECT foo
FROM (SELECT 27 AS FOO FROM dual)
WHERE foo IN(35, 45, 26, 98, 27)

returns 27

SELECT foo
FROM (SELECT 64 AS FOO FROM dual)
WHERE foo IN(35, 45, 26, 98, 27)

returns no data found

257 questions
5
votes
2 answers

Passing parameters to IN clause in SQL Server

Possible Duplicates: Parameterizing a SQL IN clause? SQL Server - In clause with a declared variable Hi, I am facing problem passing parameters to 'IN' clause. I am using the below query. Query: SELECT Topics.Topic_Id FROM Topics Where…
San
  • 1,797
  • 7
  • 32
  • 56
5
votes
1 answer

Mysql query with IN clause and limit for each item

I have a table in MySQL with a field "class_id". I need to write a query which returns top 15 rows sorted using descending time order, for each value in the list with IN clause. Query for explanation: select * from table_x where class_id IN (1,2,3)…
Sudheer
  • 327
  • 3
  • 15
5
votes
5 answers

SQL Server 2008 Update Query with Join and Where clause in joined table

Not sure why this is not working: UPDATE ust SET ust.isUnsubscribedFromSystemEmails = 1 FROM UserSetting AS ust INNER JOIN [User] ON ust.userID = [User].userID AND [User].emailAddress IN (SELECT emailAddress FROM…
toddm
  • 141
  • 1
  • 4
  • 11
5
votes
3 answers

Sql IN clause slows down performance

I need a help about sql query performance... I have a view and when I run view as select * from udv_salesAnalyze where _month=12 and _year=2012 I got result in 2 seconds but when I add another filter as select * from udv_salesAnalyze where…
Gökhan Yılmaz
  • 75
  • 1
  • 1
  • 6
5
votes
3 answers

SQL In Clause Multiple Columns

SELECT * FROM Tabl tabb WHERE (tabb.col1, tabb.col2) IN ( (1,2), (3,4)) The above works in Oracle but I am trying to run in a proprietary SQL engine which doesn't support the above query formation with multiple columns in IN. I am trying to find…
user1857647
  • 49
  • 1
  • 1
  • 3
4
votes
2 answers

Ansible Playbook - Pysnow: Find record using 'IN' clause query

I am working on ansible playbook to grab SNOW record by using snow_record_find module. The documentation (https://docs.ansible.com/ansible/latest/modules/snow_record_find_module.html) have very limited example. Besides that, I am also unable to…
Fitri Izuan
  • 350
  • 1
  • 6
  • 18
4
votes
1 answer

Are there any caveats when using column names in 'IN' clause?

I just had a need to search a particular string value in 2 columns, so my usual approach is SELECT ... FROM ... WHERE (col1 = 'xyz' OR col2 = 'xyz') But if I had to check multiple values (just for a quick check), say once for 'abc', then 'www',…
ranit.b
  • 217
  • 3
  • 8
4
votes
1 answer

Oracle - In CLAUSE question when using with multiple values, making it dynamic

I just spent an hour on google and here trying to get a straight answer for how to do this in Oracle. What I need is the ability to use select in clause that constructed automatically such as select col1 from table1 where id.table IN…
sarsnake
  • 26,667
  • 58
  • 180
  • 286
4
votes
2 answers

JPA Criteria : in clause with many columns

I am trying to write the following SQL query using the JPA Criteria API SELECT * FROM Table1 a WHERE (a.category, a.priority) IN ( SELECT a1.category, max(a1.priority) FROM Table1 a1 GROUP BY a1.category ) Functionally, the query select the element…
Manuel Leduc
  • 1,849
  • 3
  • 23
  • 39
4
votes
1 answer

JPA query for select which multiple values in the "IN" clause

I want to create a JPA parameterised query for following SQL statement select * from car where (colour, speed) in (('red', 50), ('blue', 70)) this query returns the expected result entityManager.createQuery("from Car c where (c.colour, c.speed) in…
SubOptimal
  • 22,518
  • 3
  • 53
  • 69
4
votes
3 answers

dapper sql in-clause throws exception

This may be a duplicate of SELECT * FROM X WHERE id IN (...) with Dapper ORM I am trying to achieve : connection.execute("delete from table where id in @ids", new { ids = new int[]{1,2}}); But it's not working. I always get : ERROR: 42883: operator…
user3448717
  • 73
  • 1
  • 6
4
votes
3 answers

Using uniqueidentifier with IN Clause in SQL server

I have a stored procedure that takes as an input a string of GUIDs and selects from table where table GUID IN (@Param). @Param =…
Mo T
  • 440
  • 2
  • 9
  • 30
4
votes
1 answer

SQL Server: order of returned rows when using IN clause

Running the following query returns 4 rows. As I can see in SSMS the order of returned rows is the same as I specified in the IN clause. SELECT * FROM Table WHERE ID IN (4,3,2,1) Can I say that the order of returned rows are ALWAYS the same as they…
Zsolt
  • 365
  • 3
  • 12
4
votes
2 answers

Expression Language: how to simplify this statement ("in"-like clause needed)

If would be great if I could replace ${myvar eq 'foo' or myvar eq 'bar' or myvar eq 'john' or myvar eq 'doe' or myvar eq ...} by either ${myvar in ['foo', 'bar', 'john', 'doe', ...]} or ${myvar in {'foo', 'bar', 'john', 'doe', ...}} but none of…
sp00m
  • 47,968
  • 31
  • 142
  • 252
4
votes
4 answers

How to write LINQ IN clause query which will work as LIKE operator as well?

How we can write a LINQ query for following select sql query: string brandid="1,2,3" string bodystyleid="1,2,3" ------------------- ----------------- select * from car where brandid in (brandid) and bodystyleid in…
Paul
  • 457
  • 2
  • 11
  • 26
1 2
3
17 18