sql - using group_concat with other selection criteria - mySQL -


I have two tables, arrc_PurchActivity and arrc_voucher. Multiple records per purchase per purchase activity table, together with credit card authorization Are tied. I need to return one line per purchase, and drag it from the voucher table to the field. If I only take some areas from the shopping activity table, such as:

  SELECT group_concat (voucher ID), ccAuthCode from arrc_PurchaseActivity GROUP BY CcAuthCode  

fix it Works, returning something like this:

  group_concat (voucher ID) | CCathcode ================================================= ========== | 8 AluPDN  

I need to pull in another contatenated area (voucher NBR), this time from the arr_ voucher table, where the voucher ID of the voucher table is equal to the voucher ID of the purchase table. In this case, because Voucride is an integration, I need to return a inserted column of vouchers NBC for each woucher ID in the inserted column. Clear it as a soil, is not it? What do I need for this:

  group_concat (voucher ID) | Group_concat (voucher NBR) | CcAuthCode ================================================= ================================================== ================== | ============ 610643,611139,610642 | 12345645678 | In other words, the voucher NBR for voucher ID 610643 is 123, voucher for 611139 is NBR 456, etc.  

Can someone help me? It is above my head ...

Use:

  SELECT pa.ccauthcode, GROUP_CONCAT (DISTINCT pa.voucherid) AS Vouchers, GROUP_CONCAT (v.vouchernbr) Join AR vcchernbrs from ARRC_PURCHASEACTIVITY left ARRC_VOUCHER v at v.voucherid = pa.voucherid Group pa.ccauthcode  

I have specified DISTINCT in GROUP_CONCAT for voucherid because it is possible that you will have multiple voucherbrubs for a voucher, if not, then remove DISTINCT.

LEFT JOIN ensures that you will get the ARRC_PURCHASEACTIVITY record that does not have support records in ARRC_VOUCHER . If you do not want this behavior, change "Join" to "Join".


Comments