mysql左联接返回意外行数 [英] mysql left join returns unexpected amount of rows

查看:79
本文介绍了mysql左联接返回意外行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2张桌子,

tableA has 41 rows

tableB has 3 rows

我正在尝试通过使用左联接的查询来获取这2个表的总行,但是我得到的行数(123)比预期的多(44)

I am trying to get the total rows of these 2 tables via a query using left join but i get way more rows(123) than expected(44)

查询:

SELECT COUNT(*)
    FROM tableA as u
LEFT JOIN tableB as d
    ON u.uid=d.uid
WHERE
    u.uid=912391178669
    AND
    u.deleted = 0
    AND
    d.deleted=0

表架构:

表A

id | uid |删除

id | uid | deleted

表B

id | uid |删除

id | uid | deleted

推荐答案

我已经运行了以下查询,它运行正常..U可以将其检出.

I have run the following query It is working correctly.. U can check it out.

SELECT 
  ( SELECT count(*) from table1 where.... )
+ ( SELECT count(*) from table2 where.... )
as total from dual

这篇关于mysql左联接返回意外行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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