Questions tagged [sql-in]

`SQL IN` operator allows us to specify multiple values in a WHERE clause.

SQL IN operator allows us to specify multiple values in a WHERE clause.

simple syntax:

SELECT * 
FROM PERSON
WHERE ID IN (1, 5, 10)

Reference

222 questions
1
vote
1 answer

SELECT NOT IN with multiple columns in subquery

Regarding the statement below, sltrxid can exist as both ardoccrid and ardocdbid. I'm wanting to know how to include both in the NOT IN subquery. SELECT * FROM glsltransaction A INNER JOIN cocustomer B ON A.acctid = B.customerid WHERE sltrxstate…
Chris
  • 33
  • 4
1
vote
1 answer

PHP-MySQL - Destroy/Disregard Table Fields if it contains no value/null

Good day! I was trying to LEFT Join one Table into Another. Is it possible to destroy or disregard table fields, for example blotter_entry if it doesn't contain any value or if it is null? By looking at the screenshot below, As you can see I have…
1
vote
1 answer

How to remove categories with no products?

I am a bit stuck on the following SQL: delete from oc_category_description where 'category_id' NOT in (SELECT category_id FROM oc_product_to_category); delete from oc_category_path where 'category_id' NOT in(SELECT category_id from…
John Dow
  • 19
  • 1
1
vote
1 answer

PostgreSQL subquery (illogical) bug in select statement with join equivalent working?

I have some funny bug with Postgres 9.5.1 I got 2 tables that contain related data contacts (id, name) and jobs (id, contact_id, name). I'm not sure of the validity of this query (given the curious behavior explained just after). -- get unassigned…
Luffah
  • 13
  • 3
1
vote
1 answer

Passing Array Parameter to SQL command javascript

I'm trying to pass a dynamic array to a executeSql. I'm passing the SQL to the IN as array. let lor_text_Array = []; if (lor_text == "TEST 1, 2, 3") { lor_text_Array = ["TEST 1", "TEST 2", "TEST 3"]; } else { lor_text_Array.push("TEST 4") …
user12448300
1
vote
2 answers

SELECT * where all of integer[] cell are in a set of values

I'm trying to solve exactly this: How to check if a cell of type integer array contains a certain value in SQL but for multiple values on boths sides so something like this: SELECT id FROM table WHERE ALL(column_of_type_integer_array) IN (2,3,4) Is…
Basti
  • 606
  • 1
  • 12
  • 22
1
vote
1 answer

How to search an enum in list of strings by postgresql query?

Consider a SQL Statement: select * from table where status in Where status is an enum: CREATE TYPE statusType AS ENUM ( 'enum1', 'enum2'; In Java I have a list of the enums in string representation: List list = new…
btbam91
  • 578
  • 2
  • 8
  • 20
1
vote
2 answers

Behavior of IN in Oracle

I have written a subquery to join two tables and fetch the data, where one ID column is common for both to join. But the column name is different as below. This one I have written: SELECT parent_id ,name FROM parent_table WHERE parent_id IN…
Mansi Raval
  • 371
  • 6
  • 14
1
vote
1 answer

Question about subqueries, why there is a need for a IN clause

Here is the given code: SELECT * FROM CUSTOMERS WHERE ID IN (SELECT ID FROM CUSTOMERS WHERE SALARY > 4500); Why we can't simply write: SELECT * FROM CUSTOMERS WHERE SALARY > 4500; ? Here is another code: SQL> INSERT INTO CUSTOMERS_BKP SELECT *…
user
  • 241
  • 1
  • 9
1
vote
1 answer

How to use the IN clause while using EntityManager with Hibernate

How do I exactly write the following query using entityManager. Select * from TABLE_NAME where column_name in ('A', 'B'); I tried with the setParametrList() method. However, it says that this method is not available for type Query. Query query =…
Saurabh Tiwari
  • 4,632
  • 9
  • 42
  • 82
1
vote
2 answers

ANY operator has significant performance problem when using an array as a parameter

I started using 'ANY()' function in query instead of 'IN' due to some parameter bound error. Currently it's something like that. Select * FROM geo_closure_leaf WHERE geoId = ANY(:geoIds) But it has a huge impact on performance. Using the query…
Ved
  • 11
  • 4
1
vote
2 answers

Multiple columns on left side of IN condition

This is a valid statement: SELECT foo FROM table1 WHERE column1 IN (SELECT bar FROM table2) AND column2 IN (SELECT bar FROM table2) But is there any way we can avoid repeating the SELECT bar FROM table2 statement to make it simpler and more…
tom
  • 2,137
  • 2
  • 27
  • 51
1
vote
3 answers

Two subselect into "IN" (oracle, sql)

How can I use into "IN" two subselect? I have now: select colA, colB from table1 where colC in (select T1 from tableT1 where colx = 'Y') and ColD = 'Y'; I need too also that colC will be into second…
4est
  • 3,010
  • 6
  • 41
  • 63
1
vote
1 answer

How to pull up records which have only gmail, hotmail, yahoo email addresses in SQL Server 2014?

I have a list of records in the database that have email addresses. I would like to pull up records that have only @gmail, @Hotmail and @Yahoo email addresses. I also want the records sorted by domain name. My code: SELECT [AccountId] …
user1777929
  • 777
  • 1
  • 10
  • 28
1
vote
2 answers

SQL Server: Comparing a list of strings with wildcards using LIKE

I'm trying to find a way to compare a character field with a few string wildcards stored in a lookup table. For example, Table A is my main table. There is a column called "Code" in Table A which I need to evaluate. I want to find all rows WHERE…
Yao Z.
  • 13
  • 2