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
3 answers

using % is IN condition

Usually when one has to search in oracle for a single where condition where you don't know the exact condition we use : Select * from Table where column like '%Val%' If I have to run check for multiple condition we use IN Select * from Table where…
misguided
  • 3,699
  • 21
  • 54
  • 96
1
vote
2 answers

TSQL - Faster to use IN (list) or use NOT IN (list) for a small list?

One of my columns can only contain 4 possible values (val1, val2, val3, val4). I need to add an additional filter in the WHERE clause to exlude one of those 4 values (i.e. val4). Is it going to be faster to use NOT IN ('val4') or IN…
johntrepreneur
  • 4,514
  • 6
  • 39
  • 52
1
vote
2 answers

Can this query be made without a subquery?

Imagine these 3 tables: User Login: LoginInfo: ---- ----- ----- id:integer id:integer id:integer name:string user_id:integer login_id:integer Is is possible to select all the Users…
Geo
  • 93,257
  • 117
  • 344
  • 520
1
vote
4 answers

SQL IN working but NOT IN does not work

I have this query that will return correctly the values that are part of the IN clause, but when I change it to NOT IN, it does not return anything. Does anyone have any suggestions? select distinct CAST( w.work_area AS CHAR(4) ) || s.code_id…
1
vote
1 answer

Does the HQL IN clause only accept a limited number of values (MySQL database)?

Here is my simplified database: user_post - id - post_id (FK) post - id - link_id (FK) link - id I've a list of user_post and I wanna get for each of them the link they are linked to. Currently, I'm doin it like this: SELECT userPost.post.link…
sp00m
  • 47,968
  • 31
  • 142
  • 252
0
votes
1 answer

Searching on an array of integers

I've got a string coming in like so: '202,203,204,205,226,230,274' I want to break this string down into an array of numbers and get back all the records with those Ids. So far, I have: string[] myArray = myString.Split(','); int[] myIntArray =…
Sniffer
  • 6,242
  • 10
  • 45
  • 53
0
votes
0 answers

Select from a table where some or one of the word is matches from a given string

I'm trying to get results from one of my tables using an exploded and imploded product name using the SELECT IN statement. $prd_exp = explode(" ", $product_bname); $prd_in = implode(",", $prd_exp); $getRecipies = $conn->prepare("SELECT * FROM…
nothes
  • 1
  • 4
0
votes
3 answers

Filter records with parameters using like statement

I have a query to filter location by different regions based on postal code of that. To distinguish these regions, people must rely on the first 2 numbers of that and each region contains many different numbers (e.g: region A (1 to 25) and region B…
HaiCNCS
  • 5
  • 1
  • 5
0
votes
1 answer

How do you use a list to find a partial match in a table column with SQL?

I have a large list of reference numbers, for example: 'abc 123', 'abc 456', 'abc 789', ... The problem is that my list is missing the last digit, so when I search my datatable to see if these references from my list are in my datatable, I find not…
0
votes
2 answers

IN statement multiple columns

I want to implement the below query Select * from table1 where a in(select a,b,c,d,e from table2 order by date desc limit 5) But IN statement is allowing only 1 column.
Gulya
  • 101
  • 9
0
votes
2 answers

Why does SQLite3 return nothing when used to find the AVG, COUNT and SUM of this database?

The database is from CS50's introduction to Computer Science course, Psets 7 | Movies. https://cs50.harvard.edu/x/2022/psets/7/movies/ When I run this command: SELECT AVG(rating) FROM ratings WHERE movie_id = (SELECT id FROM movies WHERE year =…
user19916937
0
votes
1 answer

How to get data from a row if a value in a different table is null

I have a database I want to get data from. In order to get the not yet edited files, I want to create a CSV file which lists all the files if the age is NULL. This is the code I have written: def make_csv(): c,conn=connect() #get the id and…
WorldTeacher
  • 93
  • 1
  • 10
0
votes
2 answers

How to use the IN clause for multiple columns

I am using Postgres and I would like to put together the following sql queries select * from t1 where type=57 and idt=2001 and date=1; select * from t1 where type=59 and idt=2001 and date=1; select * from t1 where type=57 and idt=2002 and…
Tms91
  • 3,456
  • 6
  • 40
  • 74
0
votes
1 answer

SQL query for EXCEPT or NOT IN

I'm new to SQL and I am trying to write a query on PostgreSQL to find the cust_ID and customer name of each customer at the bank who only has a loan at the bank, and no account. The database schema is: The results should have only these 3…
MCly
  • 105
  • 7
0
votes
1 answer

Clickhouse SQL: IN operator fails on the empty parenthesized list of expressions

Using ClickHouse, my query is failing if I pass into the query an empty set to IN clause. This works: SELECT 1 WHERE '2' IN ('2','3'); This fails: SELECT 1 WHERE '2' IN (); Error: Expected one of: token, DoubleColon, non-empty parenthesized list…
xmar
  • 1,729
  • 20
  • 48