php - MySql 查询 "Following/Follower"系统,[PHP]

标签 php mysql sql

大家好,我正在使用 MySQL 和 PHP 制作关注者/被关注系统,所以我想获取我关注的用户的所有视频并按 ID 描述排序。

数据库架构: enter image description here

例如,如果我的 user_id = 1,并且如果我正在关注 user_id = 3 的用户; 5; 我只想查看来自 publisher_id = 3; 的视频5;

最佳答案

使用 join将表格链接在一起,然后使用 where 将视频限制为仅限您的关注者。

select * 
from user_followers as uf 
join videos as v 
on uf.followed_id = v.publisher_id 
where uf.follower_id = ? 

Generally, the ON clause serves for conditions that specify how to join tables, and the WHERE clause restricts which rows to include in the result set.

关于php - MySql 查询 "Following/Follower"系统,[PHP],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44027144/

相关文章:

php - 米克罗数据库 : how to perform a replace with where statement instead of primary key

php - 客房和可用日期 PHP/MySQL

mysql - SQL 是有效的,但是有什么方法可以使它更小(包括 sqlfiddle)

mysql - 如何从MYSQL数据库中恢复已删除的行

python - Pyspark:选择除特定列之外的所有列

javascript - ChartJS 根据日期更改显示的数据?

php - Laravel Assets URL 忽略 https

JOIN 依赖于 CASE 的 MySQL 查询

mysql - 使用 like 和 concat 更新列

php - 在 prestashop DB 的表内复制