开发者

how to getting number of records after union operation..?

开发者 https://www.devze.com 2023-02-15 04:19 出处:网络
I have a query like this: select author1 from books_group where category=\'cse\' union select author2

I have a query like this:

select author1 
from books_group 
where category='cse' 
union 
select author2 
from books_group 
where category='cse' 
union 
select author3 
from books_group 
where category='cse'

the above query union the all the records that are comes from three select commands..

my task is to count the number of reco开发者_Python百科rds we have after the execution of above sql command...

and i trying the below query but it gives an error..

" select count(*) from (select author1 from books_group where category='cse' union select author2 from books_group where category='cse' union select author3 from books_group where category='cse') "

then, how to get the number of recors after the union operation..???


You were close, you need to specify an alias for your subselect:

select
    count(*)
from
    (
    select author1 from books_group where category='cse' union
    select author2 from books_group where category='cse' union
    select author3 from books_group where category='cse'
    ) a


Try this:

    select count(*) from 
(select author1 from books_group where category='cse' 
union 
select author2 from books_group where category='cse' 
union 
select author3 from books_group where category='cse')A
0

精彩评论

暂无评论...
验证码 换一张
取 消