Avinash Sharma
Avinash Sharma

Reputation: 111

Sqlite fetch from table

I have a table named Text_Field which consists of a column named ID,

I have another table named Content which consists of a table named value,

I want to fetch those values of ID from the Text_Field table which are present in the value column of the Content and satisfying a said condition.

I know I can construct a query like this

SELECT ID 
FROM Text_Field 
WHERE ID IN (
    SELECT value 
    FROM CONTENT 
    WHERE USER='CURRENT_USER')

My only problem is that for some scenarios the value table might contain the ID inside a string

So the inner query might return something like

56789
12334
12348
Rtf(833405)

Now if my ID is 833405 it is present in the value column but the IN query would return false,

I tried

group_concat(value)

So that the inner query returns a single row which is a string,

56789,12334,12348,Rtf(833405)

I want to know that after group_concat can I use something as LIKE to satisfy my need Or is there some other way I can do this?

Upvotes: 0

Views: 49

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269923

Use exists instead, with like:

SELECT t.ID 
FROM Text_Field t
WHERE EXISTS (SELECT 1 
              FROM CONTENT c
              WHERE c.USER = 'CURRENT_USER' AND
                    (c.value = t.id OR 
                     c.value LIKE '%(' || t.id || ')%'
                    )
             );

Note:

Upvotes: 1

Related Questions