加入MySQLi以获取多个表数据 [英] Joins In MySQLi for fetching multiple tables data

查看:102
本文介绍了加入MySQLi以获取多个表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表用户,并且要关注.我想编写一个视图,以便它将获取perticuler用户的所有详细信息以及这两个额外的列,作为关注者计数和关注者计数别名.

I have two table user and follow.I want to write view such that it will fetch all details of perticuler user along with that two extra column as follower count and followee count alias.

例如user id = 11,然后是用户表中的所有详细信息,再加上followcount 1和count1

eg. user id=11 then all details from user tables plus followcount 1 and followed count1

推荐答案

SELECT u.id, 
       u.userid, 
       u.name, 
       u.mobile, 
       (SELECT Count(*) 
        FROM   follow f 
        WHERE  f.followerid = u.userid) AS follower, 
       (SELECT Count(*) 
        FROM   follow f 
        WHERE  f.followeeid = u.userid) AS followee 
FROM   users u 

这篇关于加入MySQLi以获取多个表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆