0

I am using below query for fetching result using union of two tables.
I am trying to get total number of records after union of two tables
Need Suggestions.

`

SELECT a.*
FROM svn_headline a where a.newstypeid=2
UNION
SELECT b.*
FROM svn_crimenews b where b.newstypeid=2 order by newsdatetime desc




SELECT count(a.newsid)
FROM svn_headline a where a.newstypeid=2
UNION
SELECT count(b.newsid)
FROM svn_crimenews b where b.newstypeid=2 order by newsdatetime desc

`

3
Contributors
4
Replies
14
Views
3 Years
Discussion Span
Last Post by pritaeas
0
SELECT SUM(num) FROM
(
    SELECT COUNT(*) num FROM svn_headline a where a.newstypeid=2
    UNION
    SELECT COUNT(*) num FROM svn_crimenews b where b.newstypeid=2
)
0

Getting error

1248 - Every derived table must have its own alias

0

u can save in a temp table as shown follow

SELECT a.* into Temp_Table
FROM svn_headline a where a.newstypeid=2
UNION
SELECT b.*
FROM svn_crimenews b where b.newstypeid=2 order by newsdatetime desc

and then by count of temp table u get total records

Select count(*) from Temp_Table

Edited by pritaeas: Added markdown.

0
SELECT SUM(num) FROM
(
    SELECT COUNT(*) num FROM svn_headline a where a.newstypeid=2
    UNION
    SELECT COUNT(*) num FROM svn_crimenews b where b.newstypeid=2
) Dummy
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.