主外键关联跟记录数没啥关系啊。除非你业务上有什么逻辑,要不无异于一条语句差两张无关表的记录数。倒是可以不做关联的情况下分别count两张表的一个字段,但是会非常非常慢啊~不知道什么限制你非要用一条sql,要是分别count会快很多啊。
select count(*) from table_a
union
select count(*) from table_b
这样倒是一条语句,不过我觉得你要的应该不是这个吧?
这样可以,刚想起来select (select count(*) from table_a) as A ,(select count(*) from table_b) as B from dual
用子查询
select (select count(*) from table_a) as A ,(select count(*) from table_b) as B from dual
select (select count(*) from table_a) as A ,(select count(*) from table_b) as B from dual
select cnt_p,cnt_c
from
(select count(1)cnt_p from父表) a,
(select count(1) cnt_c from 子表) b
eexzjfn4