gpt4 book ai didi

php - 如何使用 order by 左连接三个表?

转载 作者:行者123 更新时间:2023-11-29 20:27:42 25 4
gpt4 key购买 nike

我已经尝试了很多次,但每次都会出现sql语法错误,所以我将其分成两个查询,但我希望它是一个。请帮助我。以下是代码:

$pictures = $db->get_results(sprintf("SELECT imageID, image_name, image_date, username, userID 
FROM images LEFT JOIN users ON images.image_user = users.userID
WHERE show_in_gallery = 'Y' AND image_user = '%d'
ORDER BY imageID DESC LIMIT 0, 24", $data['userID']));
$stats = $db->get_results(sprintf("SELECT STAT.imageID, STAT.image_views,STAT.unique_views,STAT.earnings
FROM image_stats as STAT LEFT JOIN images as IMG ON STAT.imageID = IMG.imageID
WHERE image_user = '%d'
ORDER BY imageID DESC LIMIT 0, 24", $data['userID']));

这是错误:

Warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'is ON is.imageID = i.imageID WHERE show_in_gallery= 'Y' AND image_user = '8' ORD' at line 1

最佳答案

也许你想要什么?不完全确定您的尝试失败的原因。

SELECT IMG.imageID, IMG.image_name, IMG.image_date,
USR.username, USR.userID,
STAT.image_views, STAT.unique_views, STAT.earnings
FROM image_stats as STAT LEFT JOIN images as IMG
ON STAT.imageID = IMG.imageID
LEFT JOIN users as USR
ON IMG.image_user = USR.userID
WHERE image_user = '%d' AND USR.show_in_gallery = 'Y'
ORDER BY imageID DESC LIMIT 0, 24

关于php - 如何使用 order by 左连接三个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39205867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com