如何使用GROUP_CONCAT查询返回更多的一行?

时间:2013-03-04 18:00:13

标签: php mysql sql database group-concat

TXNID                PARENT_TXN_ID      ITEM_NAME
5G161631H9141883L Merchandise Total 4HD251984H4919123 Woodworking 101@Fri 04-05-2013 8:00 pm 4LA48638GR031562M Woodworking 101@Fri 04-05-2013 8:00 pm 6TU64611FM249252D Woodworking 101@Fri 04-05-2013 8:00 pm 7S953179AV7967542 Woodworking 101@Fri 04-05-2013 8:00 pm 04916720G2800071A Woodworking 101@Fri 04-05-2013 8:00 pm test1 4HD251984H4919123 setet

以上是我的数据。 这是我的询问。

SELECT ppv1.*,GROUP_CONCAT(ppv2.txn_id SEPARATOR ' <BR>') GC 
from paypal_valid ppv1
LEFT JOIN (SELECT txn_id,parent_txn_id from paypal_valid where parent_txn_id!='')
ppv2 ON ppv1.txn_id=ppv2.parent_txn_id
where ppv1.item_name!='Merchandise Total' and ppv1.parent_txn_id=''

这只返回1行......我认为它应该返回5.我只是不确定为什么只返回一行。

1 个答案:

答案 0 :(得分:1)

使用group by

尝试此操作
 SELECT ppv1.*,GROUP_CONCAT(ppv2.txn_id SEPARATOR ' <BR>') GC 
 from paypal_valid ppv1
LEFT JOIN (SELECT txn_id,parent_txn_id from paypal_valid where parent_txn_id!='')
 ppv2 ON ppv1.txn_id=ppv2.parent_txn_id
where ppv1.item_name!='Merchandise Total' and ppv1.parent_txn_id=''
group by ppv1.txn_id
                ^^^-------//make sure u have this in your ppv1 table