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

Get distinct members for an array of group IDs

I have 3 tables: Scorecard Group Scorecard_Group (Joint table) I am trying to write a query that fulfills the following purpose: Get the list of distinct scorecard ids WHERE Scorecard_Group.groupId IN (Pass array of groupIds) Get all…
Charles Semaan
  • 304
  • 2
  • 13
1
vote
1 answer

delete all rows keep only one per hour group by strftime

I have a Home Assistant sqlite file. My problem is that it grows fast and reaches enormous dimensions. So I made a php script that cleans it every 24 hours. I delete old and irrelevant data and leave only the data I need. In addition I wanted to…
Elidor
  • 172
  • 1
  • 21
1
vote
1 answer

SQLITE - Test if all rows returned from a SELECT have the same value for a particular column

I have the following table id || foo ------------- 1 || a 2 || b 3 || b 4 || b 5 || c 6 || a 7 || d Given a list of IDs, how can I test whether all of those records have the same foo…
Robert W
  • 115
  • 1
  • 6
1
vote
1 answer

Checking multiple columns for single value and returning only the single value

I want to search for a single value in 3 columns and return each occurrence of this value. My query is based on the following answer regarding a similar request. SELECT * FROM table WHERE 'abc' IN (column1, column2, column3) However, I don't want…
HJA24
  • 410
  • 2
  • 11
  • 33
1
vote
2 answers

SELECT from Multiple IF conditions in Where Clause

I have a following query SELECT * FROM products a, productImgs b WHERE a.visible = 1 AND a.Type IN ('Accessories', 'Clothing', 'Electronics') ORDER BY a.visibleOrder ASC LIMIT 100 In the above query I need to add IF condition that IF a.Type is…
user1997076
  • 69
  • 1
  • 10
1
vote
1 answer

Find duplicate values based on specific criteria

I am sorry in advance if this question has already been answered. I am still pretty new to SQL. I have a database that contains client data. Each row in the database contains a customer_number and a end_record_date (which is either a date in the…
JB1989
  • 35
  • 6
1
vote
1 answer

How to match elements in an array of composite type?

Let's say we have two tables: CREATE TABLE element ( pk1 BIGINT NOT NULL, pk2 BIGINT NOT NULL, pk3 BIGINT NOT NULL, -- other columns ... PRIMARY KEY (pk1, pk2, pk3) ); CREATE TYPE element_pk_t AS ( pk1 BIGINT, pk2…
Ziqi Liu
  • 2,931
  • 5
  • 31
  • 64
1
vote
1 answer

Getting one row insted of multiple rows when using query statment inside in() at where clause

There are two tables fruits and fruits_seasons in the schema and I wanted to get all the monsoon fruits. While trying so I noticed a weird response. https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=77d52b2736a04a5adf4ffe80881cd4ab Monsoon months select…
Suvel Mano
  • 23
  • 4
1
vote
2 answers

Filter Id that contain specific values in columns in MS Access

I am trying to filter rows from a table in MS Access using Query but with no success. I have below table below, I would like to generate a query based on the values "A1" and "A2" in any of the columns KH1 to KH6 columns. The results should look like…
KApril
  • 632
  • 1
  • 8
  • 20
1
vote
2 answers

Sqlite SELECT with multiple conditions

I have to create a database with a PRODUCTS table and a CATEGORIES table. Each product has a name, a price, a creation date and may belong to several categories. Categories have a name and a flag to indicate whether the category is private or…
Laurent
  • 31
  • 1
  • 5
1
vote
2 answers

UPDATE multiple row in SQLITE

I'm using SQLite and I'm trying to update multiple row using a select statement. I'm having two tables: device : ID|Name|param1|param2 ---------------------- 1 | D1 | p1 | p2 2 | D2 | p1 | p3 3 | D3 | p1 | …
Shaarkrat
  • 37
  • 3
1
vote
1 answer

Select fields from a table which satisfy condition in another table

A sqlite database has the two following tables: table1 table2 --------- --------- f1 | f2 e | f --------- --------- 0 | 1 0 | 1 2 | 3 0 | 2 1 | 4 0 …
amrsa
  • 215
  • 2
  • 9
1
vote
1 answer

Is there way to combine as and in SQL Server

select ptidentifier, patientname, patientage, patientcreditcards from patients with (nolock) where ptidentifier like '%3026737%' Let's say I have like 20 different patient identifier, in order to an like, I need to insert one at a time, is there…
SQLluv8832
  • 11
  • 4
1
vote
2 answers

MySQL doesn't use the index I expect when my query has a large number of values in `IN` clause

I have a problem when IN clause contains too many values. Consider this query EXPLAIN SELECT DISTINCT t.entry_id , t.sticky , wd.field_id_104 , t.title FROM exp_channel_titles AS t LEFT JOIN exp_channels ON t.channel_id =…
Oleksandr IY
  • 2,783
  • 6
  • 32
  • 53
1
vote
3 answers

PostgreSQL how to treat null as a value

Let us say: I have a table with the name "movie" and it contains a field with the name "categoryid" which points to another "category" table. The field "categoryid" can be null in case no category was selected for a movie. Otherwise it's a…
Menas
  • 1,059
  • 1
  • 9
  • 19