A
A
Alexey Nikolaev2015-06-02 22:29:08
SQL
Alexey Nikolaev, 2015-06-02 22:29:08

Is it possible to select a row with a single request by the condition of the presence of the required ID in the field if the IDs are written separated by commas in one line?

Good evening.
There is a field ids (table A), in which IDs of records of another table B are listed, separated by commas. I am trying to display all fields in which B.id values ​​will be present in A.ids with one request. In the evening, I don’t understand at all - LOCATE in this situation is poorly suited (you will have to run at least 2-3 checks), procedures (to break the field value with IDs into an array and use the IN operator) are more likely not an option than an option, because program execution priority. Is there a nice way to solve the problem?
The database engine is sqlite .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-06-02
@Rsa97

Refactor and bring all tables into normal form.

A
Alexey Rytikov, 2015-06-03
@chlp

If I understand correctly and look for id=5:

SELECT * FROM A where A.ids = '5' OR A.ids like '5,%' OR A.ids like '%,5,%' OR A.ids like '%,5'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question