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

Match a list of patterns using SQL IN and LIKE

Is it possible to match a list of patterns in SQL? I know of the following way to match a single pattern: SELECT * FROM table where title LIKE '%match%' This can be exbanded like; SELECT * FROM table where title LIKE '%match%' OR title LIKE…
0
votes
3 answers

Deleting records in MySQL WHERE id IN (@VARIABLE) -- (2,3,4)

Is there is a way to delete records using WHERE IN @VARIABLE? -- DEMO TABLE CREATE TABLE people ( id int AUTO_INCREMENT NOT NULL, name varchar(100), age int, active smallint DEFAULT 0, PRIMARY KEY (id) ); -- DEMO DATA INSERT…
DevWL
  • 17,345
  • 6
  • 90
  • 86
0
votes
1 answer

How to fetch data only if both user are friend from sql server

Here is my database structure. User table -user_id -fname -lname profile table -profile_user_id -profile_id -profile_id friend_request table -id -from_id -to_id -status my query is SELECT fname,lname,profile FROM user LEFT JOIN profile ON…
Debaraj Stha
  • 1
  • 1
  • 5
0
votes
1 answer

Is there an easy way to filter result by combining both like %% and in together using OR? I could not find a way

select authorname from library where author like '%ROSARIO RAMIREZ CORTE%' or author like '%Ann Rice%' Since the Excel sheet I have doesn't provide the exact match of author name, that's why I want to use like and I was able to find the…
0
votes
2 answers

SQLAlchemy: Is it possible to combine "like" and "in" within the same query

I have the following SQLAlchemy query working incomplete_list = ['a','b','c'] complete_units = [] for elem in incomplete_list: query = Table.query.filter(Table.name.like(elem)) for row in query: …
TheEmperor
  • 335
  • 2
  • 12
0
votes
1 answer

Does Actian PSQL 13.31 (Zen) have the equivalent of SQL Server "IN" in WHERE clause?

I have read a ton of Actian PSQL docs but cannot find out how to duplicate this simple SQL verb: SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...); Does Actian PSQL 13.31 have the equivalent of SQL Server IN in the…
0
votes
2 answers

How to get a row from a look up table column contains any

I have a Customer table with the following rows in it: I have a Lookup table called Master as below: As you can see in the Master look up I have first name shown with a middle name. What is best SQL quesry to give me the following result: So…
Balaip
  • 31
  • 4
0
votes
2 answers

SQL "NOT IN" function not working properly

Hi can anyone figure out what's wrong with this sql query. The Not In function is not working properly. in my table the id 1 and 2 should not fetched as they come in subquery in the not in function. select pr.id ,pc.title as category …
0
votes
1 answer

How to have different values of a single column in a condition where in sql?

I write a SQL query to get different sales information about stores. The problem is that I would like to filter and take only some store numbers in my "GL_ETABLISSEMENT" column, if I just do AND (GL_ETABLISHMENT = "20897") it works but not if I add…
Theo27
  • 385
  • 4
  • 17
0
votes
2 answers

Difficulty using an array as part of PDO "IN" query

I'm trying to query a MySQL databse using an array. $array=array('Group1','Group2','Group3'); $inQuery=implode(",",$array); //$inQuery='Group1'; //This returns the expected result, but is obviously not an array $data=array($inQuery); try { $STH =…
Matt
  • 7,022
  • 16
  • 53
  • 66
0
votes
1 answer

SQL Query for Selecting multiple rows with multiple column value

I want to do the following in the db2 SQL select * from table where column =(value1,value2,value3) result should return all the rows with all columns for the given table whose column values is value1,value2 and value3
panacea
  • 11
  • 1
0
votes
1 answer

Search function on multiple rows in the same table

I'm wondering how do I add more row's on my search script to be searched. Here's my php script:
0
votes
2 answers

SQL In Clause with 20000 values

I have a xls with 20000 IDs I need to extract the rows of a table that have these IDs in Col1 Is there a clever way to do this in Oracle SQL ? I only have a read access to this db. I thought to slice the 20000 IDs, in order to put the first 1000 in…
Largo7321
  • 15
  • 4
0
votes
1 answer

How to Exclude Multiple Values with Respective Sub Values in WHERE Clause - SQL

I'm trying to exclude certain subvalues from specific values. To be specific, I have a column that corresponds to maintenance locations (i.e. 'A', 'B', 'C'...) and another that corresponds to jobs at those maintenance locations (i.e. '05', '06',…
Rene
  • 1
0
votes
3 answers

How do I not repeat myself in this SQL query?

I've started learning SQL and I'm trying to reduce my repetition. Can someone help with this? SELECT email FROM users WHERE campaign LIKE 'BBB-2' AND test ='lions' OR test = 'tigers' OR test = 'bears';