Total row count from two different tables.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • plzansmyquery
    New Member
    • Mar 2008
    • 4

    Total row count from two different tables.

    Hello,

    I am fresher to SQL Server. please help me with below query.

    does any one know how to get the total number of rows from two different tables in a single query.

    For ex: Table1 has 'x' rows & table to has 'y' rows, then I want the total 'x+y' rows value in a single query.

    thanks in advance.
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by plzansmyquery
    Hello,

    I am fresher to SQL Server. please help me with below query.

    does any one know how to get the total number of rows from two different tables in a single query.

    For ex: Table1 has 'x' rows & table to has 'y' rows, then I want the total 'x+y' rows value in a single query.

    thanks in advance.
    Try this:

    [code=sql]

    SELECT SUM(cnt) FROM
    (SELECT COUNT(*) AS cnt from tablex
    UNION ALL
    SELECT COUNT(*) FROM tabley)

    [/code]

    Comment

    Working...