mysql 查询仅在行数大于零时返回
如何更改此查询以仅返回返回多于 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;
编辑从评论中添加有用信息:
表albumData 为每个用户、每张照片存储唯一的行 他们已经设置了专辑,这是我要返回专辑数量的地方 从最初开始的行。不过我想将 albumData 中的 id 与 albumID 是相册表,如果行数带有 albums.albumID=albumData.id 大于 1,然后返回这些行。
How can I change this query to only return rows that return more than 0 rows?
I need to combine these two queries. I need to return rows where the second query returns at least 1 row.
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;
EDIT add useful information from comments:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
下次尝试..如果我理解问题正确的话
next try .. if I understand the problem right
我假设你遇到了某种错误..
如果你试图阻止空记录集:
使用这样的东西
Im going to assume your getting some kind of error..
if your trying to prevent a null recordset:
use someything like this
您的查询似乎正确。
下面可能会出现问题...
没有记录等于
$id
AND$albumID
。请先手动检查并再次执行查询...祝你好运!!!
Your query seems CORRECT.
Below might be problem...
There are NO records that equal
$id
AND$albumID
. Please check this manually first and execute query again...Good Luck!!!