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
精彩评论