FIND_IN_SET() 检查 id 后,它就像是两个不同的帖子
FIND_IN_SET() After checking the id's it's acting like it's two different posts
这里是 DEMO 以便更好地理解问题所在。
以下 sql 查询仅打印 i_user_uploads table 中具有 uploaded_file_ext
的 mp3 值的查询。从查询中可以理解,i_user_uploads
中的数据取自i_posts
table.
中的post_file
个id
我需要做一些澄清以便更好地理解。
post_file实际上由i_user_uploads
table中的upload_ids
组成。例如,post_file 2,14
实际上代表了i_user_uploads
中的upload_id
。如果你看一下DEMO.
中的图表会更容易理解
查询中的输出应该是这样的。 post_file 中的 upload_ids 应该跟在屏幕上 i_user_uploads
table 中的 uploaded_file_ext = 'mp3'
应该打印在屏幕上。
更详细地解释一下,post_file 1
实际上是i_user_uploads
table中的upload_id 1
。如果这个 id
中的 uploaded_file_ext
是 mp3
,那么屏幕上会打印出来。
问题是如果级联的 id 包含 mp3,输出的行为就好像有多个 post_id。所以它重复相同的 post_id
.
请检查此 和 DEMO 页面.你会更好地理解。
SELECT P.*,U.*,A.*
FROM i_friends F FORCE INDEX(ixFriend)
INNER JOIN i_posts P FORCE INDEX (ixForcePostOwner)
ON P.post_owner_id = F.fr_two
INNER JOIN i_users U FORCE INDEX (ixForceUser)
ON P.post_owner_id = U.iuid AND U.uStatus IN('1','3') AND F.fr_status IN('me', 'flwr', 'subscriber')
INNER JOIN i_user_uploads A FORCE INDEX (iuPostOwner)
ON P.post_owner_id = A.iuid_fk
AND P.post_file <> '' AND A.uploaded_file_ext = 'mp3'
WHERE P.post_owner_id='1'
AND FIND_IN_SET(A.upload_id, P.post_file)
ORDER BY P.post_id
DESC LIMIT 5
如果您想要每个 post id 一行,您需要做的是 GROUP BY post_id
。
但是,由于 Post #6 上载有多个 MP3,您需要做出商业决定。你想要哪个MP3?或者你想把它们都放在一个列表中吗?
您做出决定,然后使用 GROUP_CONCAT 或 FIRST
等分组函数
所以要列出所有 MP3,GROUP_CONCAT 很可能是您想要的:
SELECT P.*,U.*,GROUP_CONCAT(A.uploaded_file_path)
FROM i_friends F FORCE INDEX(ixFriend)
INNER JOIN i_posts P FORCE INDEX (ixForcePostOwner)
ON P.post_owner_id = F.fr_two
INNER JOIN i_users U FORCE INDEX (ixForceUser)
ON P.post_owner_id = U.iuid AND U.uStatus IN('1','3') AND F.fr_status IN('me', 'flwr', 'subscriber')
INNER JOIN i_user_uploads A FORCE INDEX (iuPostOwner)
ON P.post_owner_id = A.iuid_fk
AND P.post_file <> '' AND A.uploaded_file_ext = 'mp3'
WHERE P.post_owner_id='1'
AND FIND_IN_SET(A.upload_id, P.post_file)
GROUP BY P.post_id
ORDER BY P.post_id
DESC LIMIT 5
这里是 DEMO 以便更好地理解问题所在。
以下 sql 查询仅打印 i_user_uploads table 中具有 uploaded_file_ext
的 mp3 值的查询。从查询中可以理解,i_user_uploads
中的数据取自i_posts
table.
post_file
个id
我需要做一些澄清以便更好地理解。
post_file实际上由i_user_uploads
table中的upload_ids
组成。例如,post_file 2,14
实际上代表了i_user_uploads
中的upload_id
。如果你看一下DEMO.
查询中的输出应该是这样的。 post_file 中的 upload_ids 应该跟在屏幕上 i_user_uploads
table 中的 uploaded_file_ext = 'mp3'
应该打印在屏幕上。
更详细地解释一下,post_file 1
实际上是i_user_uploads
table中的upload_id 1
。如果这个 id
中的 uploaded_file_ext
是 mp3
,那么屏幕上会打印出来。
问题是如果级联的 id 包含 mp3,输出的行为就好像有多个 post_id。所以它重复相同的 post_id
.
请检查此
SELECT P.*,U.*,A.*
FROM i_friends F FORCE INDEX(ixFriend)
INNER JOIN i_posts P FORCE INDEX (ixForcePostOwner)
ON P.post_owner_id = F.fr_two
INNER JOIN i_users U FORCE INDEX (ixForceUser)
ON P.post_owner_id = U.iuid AND U.uStatus IN('1','3') AND F.fr_status IN('me', 'flwr', 'subscriber')
INNER JOIN i_user_uploads A FORCE INDEX (iuPostOwner)
ON P.post_owner_id = A.iuid_fk
AND P.post_file <> '' AND A.uploaded_file_ext = 'mp3'
WHERE P.post_owner_id='1'
AND FIND_IN_SET(A.upload_id, P.post_file)
ORDER BY P.post_id
DESC LIMIT 5
如果您想要每个 post id 一行,您需要做的是 GROUP BY post_id
。
但是,由于 Post #6 上载有多个 MP3,您需要做出商业决定。你想要哪个MP3?或者你想把它们都放在一个列表中吗?
您做出决定,然后使用 GROUP_CONCAT 或 FIRST
等分组函数所以要列出所有 MP3,GROUP_CONCAT 很可能是您想要的:
SELECT P.*,U.*,GROUP_CONCAT(A.uploaded_file_path)
FROM i_friends F FORCE INDEX(ixFriend)
INNER JOIN i_posts P FORCE INDEX (ixForcePostOwner)
ON P.post_owner_id = F.fr_two
INNER JOIN i_users U FORCE INDEX (ixForceUser)
ON P.post_owner_id = U.iuid AND U.uStatus IN('1','3') AND F.fr_status IN('me', 'flwr', 'subscriber')
INNER JOIN i_user_uploads A FORCE INDEX (iuPostOwner)
ON P.post_owner_id = A.iuid_fk
AND P.post_file <> '' AND A.uploaded_file_ext = 'mp3'
WHERE P.post_owner_id='1'
AND FIND_IN_SET(A.upload_id, P.post_file)
GROUP BY P.post_id
ORDER BY P.post_id
DESC LIMIT 5