将一行与空值合并为另一行mysql的空值

时间:2014-10-14 05:05:53

标签: mysql

我想将两行合并为一个。以下格式在数据库中。

+----+---------+-----------------------+-------------------------+
| id |  appid  |        photo          |         signature       |
+====+=========+=======================+=========================+
| 1  | 10001   | 10001.photograph.jpg  |    NULL                 |
| 2  | 10001   | NULL                  |    10001.signature.jpg  |
+----+---------+-----------------------+-------------------------+

我想要一个mysql查询,以便我可以获取如下所示的数据

  +--------+------------------------+-------------------------+
  | appid  |  photo                 |    signature            |
  +========+========================+=========================+
  |10001   | 10001.photograph.jpg   |   10001.signature.jpg   |
  +--------+------------------------+-------------------------+

请建议......

2 个答案:

答案 0 :(得分:1)

您还可以使用max功能

select appid,
max(photo) photo,
max(signature) signature
from test
group by appid

Demo

答案 1 :(得分:0)

这应该这样做:

select t1.appid,t1.photo,t2.signature from mytable t1 join mytable t2 on t1.appid=t2.appid where t1.id=1 and t2.id=2