php - mysql select count 与另一个 select count

标签 php mysql database select

如何在 mysql 中合并这两个查询?

 select count(*) as entry_count from tbl_entries where user_id = x

select username, avatar from tbl_users where user_id = x

我想要一个结合这 2 个查询结果的结果。请帮帮我!

谢谢!

最佳答案

select username, 
       avatar,
       (select count(*) from tbl_entries where user_id = x) as entry_count
from tbl_users 
where user_id = x

关于php - mysql select count 与另一个 select count,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9273607/

相关文章:

php - 带有 anchor 标记的 CodeIgniter 文件上传问题

sql - 从一个表中获取另一表中没有记录的记录

mysql - 获取最后的日志条目

sql - 移动数据库后存储过程卡住

mysql - 为什么当我尝试创建此表时出现此 FK 错误?错误号 : 150 "Foreign key constraint is incorrectly formed

php - RESTful API 的 nginx 配置

C# dll,可与 php 和 java 互操作

php - 向用户显示错误或 php + mysql 代码。可以提取哪些信息以及如何防止这种情况?

php - 一页显示多个 COUNT(*)

MySQL REGEX 表示一个换行符