gpt4 book ai didi

仅当行数大于零时,mysql 查询才返回

转载 作者:行者123 更新时间:2023-11-30 23:34:12 25 4
gpt4 key购买 nike

如何将此查询更改为仅返回返回多于 0 行的行?

我需要结合这两个查询。我需要返回第二个查询至少返回 1 行的行。

    SELECT albumData.* 
FROM albumData
WHERE userID='$id'
AND state='0'
ORDER BY date DESC


SELECT photos.photo
FROM albums, photos
WHERE albums.userID = '$id'
AND albums.photoID = photos.id
AND albums.albumID = $albumID
ORDER BY photos.id DESC LIMIT 6;

编辑 从评论中添加有用的信息:

Table albumData containers unique rows, for each user, for each photo album they have set up, this is where I want to return the number of rows from initially. However I want to compare the id in albumData to albumID is albums table, if the number of rows with albums.albumID=albumData.id is more than one, then return those rows.

最佳答案

下一步尝试.. 如果我理解正确的话

SELECT photos.photo 
FROM albums
INNER JOIN photos on albums.photoID = photos.id
INNER JOIN albumData ON albumData.id = albums.albumID
WHERE albums.userID = '$id'
and albums.albumID = $albumID
and albumData.state = '0'
ORDER BY photos.id DESC LIMIT 6;

关于仅当行数大于零时,mysql 查询才返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8960360/

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