简体   繁体   English

MySQL查询添加另一个条件

[英]MySQL Query adding another condition

Here is my query: 这是我的查询:

SELECT photos.*
FROM photos
INNER JOIN follows
ON photos.userid=follows.followingid
WHERE follows.followerid = $myId
ORDER BY photos.id
DESC LIMIT 10

How would I add an extra condition to this correctly so that it can check for photos by that user's ID (using the $myId variable)? 我如何正确地为此添加一个附加条件,以便它可以通过该用户的ID(使用$ myId变量)检查照片?

UPDATE: Now added the conditional in the syntax provided in an answer, but only shows images from users you're following not your own photos though. 更新:现在在答案中提供的语法中添加了条件语句,但仅显示来自您正在关注的用户的图像,而不是您自己的照片。

UPDATE 2: Table structures: 更新2:表结构:

表:照片

表:如下

From your question it is difficult to gather how your tables are set up, but this may be what you're looking for: 根据您的问题,很难收集表的设置方式,但这可能是您要查找的内容:

SELECT photos.*
FROM photos
LEFT OUTER JOIN follows
ON photos.userid=follows.followingid
WHERE follows.followerid = $myId OR photos.userid = $myId
ORDER BY photos.id
DESC LIMIT 10

EDIT: I see what you're trying to do, you need to do a left outer join to include every result from the photos table, this should work. 编辑:我看到您正在尝试做的事情,您需要做一个左外部联接,以包括photos表中的每个结果,这应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM