私はこれに何日も立ち往生しているので、あなたの誰かが助けてくれるかどうか疑問に思っていました.
この規模でクエリを作成しようとしたのはこれが初めてです。
私はソーシャルネットワークを作成しており、人々が何かを好きになったり、何かにコメントしたりしたことを示すアクティビティフィードのクエリを実行しています。誰かがステータスに返信したときとは別に、すべて動作しています。
私がやりたいのは、関連するコメントを関連するステータスに添付することですが、これは機能しますが、元のステータスの重複したエントリが表示されます。以下のクエリを参照してください
SELECT
d1.d_id AS d1_d_id, d1.profile_picture AS d1_profile_picture, d1.username AS d1_username, d1.forename AS d1_forename, d1.surname AS d1_surname,
d2.d_id AS d2_d_id, d2.profile_picture AS d2_profile_picture, d2.username AS d2_username, d2.forename AS d2_forename, d2.surname AS d2_surname,
d3.d_id AS d3_d_id, d3.profile_picture AS d3_profile_picture, d3.username AS d3_username, d3.forename AS d3_forename, d3.surname AS d3_surname,
d4.d_id AS d4_d_id, d4.profile_picture AS d4_profile_picture, d4.username AS d4_username, d4.forename AS d4_forename, d4.surname AS d4_surname,
a.ra_id AS ra_id, a.r_id AS r_id, a.comment AS a_comment, a.type AS a_type, a.status AS status, a.date_posted AS date_posted,
ar.r_id AS ar_r_id, ar.comment AS ar_comment, ar.type AS ar_type, ar.status AS ar_status, ar.date_posted AS ar_date_posted,
c.slug AS cat_slug,
p.p_id AS p_id, p.title AS title, p.slug AS slug,
m.media_path AS p_media_path,
m1.i_id AS m1_i_id, m1.media_path AS m1_media_path,
m2.i_id AS m2_i_id, m2.media_path AS m2_media_path,
m3.i_id AS m3_i_id, m3.media_path AS m3_media_path,
m4.i_id AS m4_i_id, m4.media_path AS m4_media_path
FROM activity AS a
INNER JOIN designers AS d1 ON d1.d_id = a.d_id
LEFT JOIN media AS m1 ON m1.i_id = d1.profile_picture
LEFT JOIN projects AS p ON p.p_id = a.r_id
LEFT JOIN media AS m ON m.i_id = p.image
LEFT JOIN categories AS c ON c.c_id = p.c_id
LEFT JOIN designers AS d2 ON d2.d_id = p.d_id
LEFT JOIN media AS m2 ON m2.i_id = d2.profile_picture
LEFT OUTER JOIN designers AS d3 ON d3.d_id = a.t_id
LEFT JOIN media AS m3 ON m3.i_id = d3.profile_picture
LEFT JOIN activity AS ar ON ar.r_id = a.ra_id
LEFT JOIN designers AS d4 ON d4.d_id = ar.d_id
LEFT JOIN media AS m4 ON m4.i_id = d4.d_id
WHERE a.status != 1 AND a.type != 'Follow'
UNION
SELECT
d1.d_id AS d1_d_id, d1.profile_picture AS d1_profile_picture, d1.username AS d1_username, d1.forename AS d1_forename, d1.surname AS d1_surname,
d2.d_id AS d2_d_id, d2.profile_picture AS d2_profile_picture, d2.username AS d2_username, d2.forename AS d2_forename, d2.surname AS d2_surname,
d3.d_id AS d3_d_id, d3.profile_picture AS d3_profile_picture, d3.username AS d3_username, d3.forename AS d3_forename, d3.surname AS d3_surname,
d4.d_id AS d4_d_id, d4.profile_picture AS d4_profile_picture, d4.username AS d4_username, d4.forename AS d4_forename, d4.surname AS d4_surname,
a.ra_id AS ra_id, a.r_id AS r_id, a.comment AS a_comment, a.type AS a_type, a.status AS status, a.date_posted AS date_posted,
ar.r_id AS ar_r_id, ar.comment AS ar_comment, ar.type AS ar_type, ar.status AS ar_status, ar.date_posted AS ar_date_posted,
c.slug AS cat_slug,
p.p_id AS p_id, p.title AS title, p.slug AS slug,
m.media_path AS p_media_path,
m1.i_id AS m1_i_id, m1.media_path AS m1_media_path,
m2.i_id AS m2_i_id, m2.media_path AS m2_media_path,
m3.i_id AS m3_i_id, m3.media_path AS m3_media_path,
m4.i_id AS m4_i_id, m4.media_path AS m4_media_path
FROM activity AS a
INNER JOIN designers AS d1 ON d1.d_id = a.d_id
LEFT JOIN media AS m1 ON m1.i_id = d1.profile_picture
LEFT JOIN projects AS p ON p.p_id = a.r_id
LEFT JOIN media AS m ON m.i_id = p.image
LEFT JOIN categories AS c ON c.c_id = p.c_id
LEFT JOIN designers AS d2 ON d2.d_id = a.r_id
LEFT JOIN media AS m2 ON m2.i_id = d2.profile_picture
LEFT OUTER JOIN designers AS d3 ON d3.d_id = a.t_id
LEFT JOIN media AS m3 ON m3.i_id = d3.profile_picture
LEFT JOIN activity AS ar ON ar.r_id = a.ra_id
LEFT JOIN designers AS d4 ON d4.d_id = ar.d_id
LEFT JOIN media AS m4 ON m4.i_id = d4.d_id
WHERE a.status != 1 AND a.type = 'Follow'
ORDER BY date_posted DESC
テーブルのコメント ID でグループ化する方法を試してみましたが、ステータスと 1 つのコメントのみがフィードに表示されます。
私はアクティビティと呼ばれるテーブルを使用しています。このテーブルには、「ステータス」、「ステータス返信」、「いいね」などのエントリを持つタイプと呼ばれる列があり、返信時に r_id (一意の ID ではない) と呼ばれる列があります。元のステータスの一意の ID がここに入力されます。
私が何かを見逃していたり、もっとよく説明する必要がある場合は、私に知らせてください.
乾杯、ダン