You can try this one.
SELECT
table2.*
FROM
(SELECT string_to_array(ids, ', ') FROM table1 WHERE name =
'Peter') AS a(a),
(SELECT generate_series(1,array_upper(string_to_array(ids,
', '),1)+1,1)FROM table1 WHERE name = 'Peter') c(n),
name| ids
-
Peter| 2, 3, 4, 5
Jack| 100, 34, 3
Both name and ids are in text format.
IF you really do not want to use a link table (user_id, flag_id), you
could use an array of ints instead of a string...
---(end of broadcast)-
am Tue, dem 24.04.2007, um 14:19:05 -0700 mailte finecur folgendes:
> Hi,
>
> Here is my first table:
>
> Table1
>
> name| ids
> -
> Peter| 2, 3, 4, 5
> Jack| 100, 34, 3
>
> Both name and ids are in text format.
>
> Here is my second table
>
> Table2
>
> id | Flag |
Hi,
Here is my first table:
Table1
name| ids
-
Peter| 2, 3, 4, 5
Jack| 100, 34, 3
Both name and ids are in text format.
Here is my second table
Table2
id | Flag | Title
-
2 | Red| good
3 | Blue | poor
4 | Green| middle
id is in integer (seri