select count(*) from (select * from photos where sortid='$id' UNION 
select * from photos where parentid='$id')

解决方案 »

  1.   

    我看你上面那两条语句是从同一张表上统计sortid='$id'和 parentid='$id'的总数吧。
    你试试这样行不行
    select count(*) from photos where (sortid='$id') or (parentid='$id');
      

  2.   

    不好意思,是我理解错误!!
    您的语句是正确的!!在同一张表下实际结果跟用UNION一样!!
    既然问出了这个问题,我想更深入一些,如果在两张表的条件下,用UNION获取的记录集,用什么办法可以得到它的总和了?
      

  3.   

    select count(*) from
    (
    select * from table1
    union all
    select * from table2
    ) table3