U
U
UserTypical32021-03-17 18:45:14
Python
UserTypical3, 2021-03-17 18:45:14

How to get a value from the database by 2 elements?

Hello!
I have a database that consists of two columns (member, date)
My goal is to enter two numbers into a cell from the date column, something like 10, 18
And so that when querying date = 18 this cell is displayed, otherwise it turns out only when requesting 10, 18 the desired cell is displayed.
sqlite3
Thank you for your help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Shitskov, 2021-03-17
@UserTypical3

Sqlite has no such type as an array, so you can't query for a specific array element. Therefore, there are two options - do not use sqlite or store dates in a separate table related via a foreign key to the current one

M
mshuribitov, 2021-03-17
@mshuribitov

And what for 10 if it is necessary to deduce 18? And if you wrote down 10.18, then the value will be like that, or try using the .split function into a variable and display the necessary indices.

R
rPman, 2021-03-17
@rPman

sql databases define an array - like a table i.e. you need an array - make a linked table
table (id, member)
dates (table_id, date)
with the created foreign key index dates.table_id -> table.id,
respectively, when you request data from the table, then join them with dates using join (depending on left/right/inner join tasks)

select distinct table.id, table.member from table left join dates on table.id-dates.table_id where dates.date=18
will return one record from table if they have associated dates with value 18
distinct removes duplicates (because left join produces table multiplication, duplicating table data for each new records of dates)
ps once upon a time, where you can shitcode, I stored arrays by serializing their text through the separator ';', adding it even for the first element (i.e. ';18;19'), then by querying you can get what you need, but this is very inefficient select * from table where dates like '%;18%'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question