まったく問題なく動作する複数の結合を含む SQL ステートメントがあります。
$sql = "SELECT ni.*, GROUP_CONCAT(DISTINCT newsletter_item_receivers.value ORDER BY newsletter_item_receivers.value) AS receivers, nf.*, GROUP_CONCAT(DISTINCT nm.mailgroup_name ORDER BY nm.mailgroup_name) AS mailgroups
FROM newsletter_items ni
INNER JOIN newsletter_fields nf ON (nf.field_letter_uid = ni.letter_id)
LEFT JOIN newsletter_item_receivers ON (newsletter_item_receivers.letter_id = ni.letter_id)
INNER JOIN newsletter_mailgroups nm ON (FIND_IN_SET(nm.mailgroup_id, newsletter_item_receivers.value))
WHERE nf.field_name = 'letter_headline' AND ni.template = '". $template ."' AND deleted = 0
GROUP BY ni.letter_id
私が欲しいのは、特定のニュースレターのリンクに関する ifo を含む Newsletter_clickstat からのデータ (リンクのクリック数など) を結合することです。
入れてみた
LEFT JOIN newsletter_clickstat cs ON (cs.letter_id = ni.letter_id)
しかし、それは何もしませんでした
解決済み:
SELECT ni.*, GROUP_CONCAT(DISTINCT newsletter_item_receivers.value ORDER BY newsletter_item_receivers.value) AS receivers, nf.*, GROUP_CONCAT(DISTINCT nm.mailgroup_name ORDER BY nm.mailgroup_name) AS mailgroups, cs.*
FROM newsletter_items ni
INNER JOIN newsletter_fields nf ON (nf.field_letter_uid = ni.letter_id)
LEFT JOIN newsletter_item_receivers ON (newsletter_item_receivers.letter_id = ni.letter_id)
INNER JOIN newsletter_mailgroups nm ON (FIND_IN_SET(nm.mailgroup_id, newsletter_item_receivers.value))
LEFT JOIN newsletter_clickstat cs ON (cs.letter_id = ni.letter_id)
WHERE nf.field_name = 'letter_headline' AND ni.template = '". $template ."' AND deleted = 0
GROUP BY ni.letter_id