Answer the question
In order to leave comments, you need to log in
How to join tables in SQL based on the result of the first query?
SELECT REGEXP_SUBSTR(listinfo, ';[^;]+') as list
FROM import AS i
JOIN lists as l ON l.listid = list
WHERE i.userid = 1
Answer the question
In order to leave comments, you need to log in
SELECT *
FROM
(
SELECT REGEXP_SUBSTR(listinfo, ';[^;]+') as list
FROM import
) AS i
JOIN lists as l
ON l.listid = list
WHERE i.userid = 1
The correct option would be to normalize the `import` table and move the many-to-many relationship to a separate table.
Now your regex will return only one occurrence of listinfo for each line, and even then with a semicolon at the beginning. For example, for the string '1;2;3' your REGEXP_SUBSTR will only return ';2'.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question