Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How do I combine record with mysql or PHP

Ilham PrasetyaIlham Prasetya Member Posts: 1

I have a mysql table that looks like this:

    id |   id_item      | 
    1  |   T0001        | 
    2  |   T0002        |
    2  |   T0003        |
    3  |   T0004        |

and I change it like this

    id |    id_item           | 
    1  |   T0001,T0002        | 
    2  |   T0001,T0003        |
    2  |   T0001,T0004        |
    3  |   T0002,T0003        |
    4  |   T0002,T0004        |
    5  |   T0003,T0004        |

I am using the query:

    SELECT
        CONCAT(t1.id_item, ',', t2.id_item) AS id_item
    FROM item t1
    INNER JOIN item t2
    WHERE
        t2.id > t1.id
    ORDER BY
        t1.id,
        t2.id

but how can i save in table item_2 like this

        id |   id_item      | 
        1  |   T0001        | 
        2  |   T0002        |
        3  |   T0001        |
        4  |   T0003        |
        5  |   T0001        |
        6  |   T0004        |
        7  |   T0002        |
        8  |   T0003        |
        9  |   T0002        |
       10  |   T0004        |
       11  |   T0003        |
       12  |   T0004        |

Does anyone know how to do this by using php or mysql?

Sign In or Register to comment.