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
the above is my data.here is my query.
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。我只是不确定为什么只返回一行。
最佳答案
尝试使用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