如何将记录与mysql或PHP结合起来 [英] How do I combine record with mysql or PHP
本文介绍了如何将记录与mysql或PHP结合起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的mysql表:
id | id_item |
1 | T0001 |
2 | T0002 |
2 | T0003 |
3 | T0004 |
我这样更改
< pre lang =text> id | id_item |
1 | T0001,T0002 |
2 | T0001,T0003 |
2 | T0001,T0004 |
3 | T0002,T0003 |
4 | T0002,T0004 |
5 | T0003,T0004 |
我正在使用查询:
< pre lang =SQL> 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
我的尝试:
但我怎样才能保存在这样的表item_2中
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 |
有谁知道如何使用php或mysql做到这一点?
解决方案
你可以试试这个
INSERT IGNORE
INTO table_1
SELECT *
FROM table_2
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
What I have tried:
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?
解决方案
You can Try This
INSERT IGNORE INTO table_1 SELECT * FROM table_2
这篇关于如何将记录与mysql或PHP结合起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文