You are on page 1of 2

select

book.book_id,book.title,book_author.author_name,book.pub_name,count(*)
as "no_of_copies"
from book,book_copies,book_author
where book.book_id=book_author.book_id
group by book.book_id,book.title,book_author.author_name,book.pub_name



Results ExplainDescribe Saved SQL History


BOOK_ID TITLE AUTHOR_NAME PUB_NAME No_of _copi es
152b other colors orhan pamuk random house 7
152c my own private idaho a smith huffington 7
152d the shining stephen king hatchette 7
152a memoirs of a geisha alan golding doubleday 7
4 rows returned in 0.02
seconds


select book_id,title,author_name,pub_name
from book natural join book_author

group by book_id,title,author_name,pub_name

UNION ALL

SELECT cast(null as varchar2(50))book_id,cast(null as varchar2(50))title,cast(null as
varchar2(50))author_name,cast(SUM(no_of_copies) as varchar2(50)) as "NO_OF_COPIES"
FROM book_copies
group by book_id
BOOK_ID TITLE AUTHOR_NAME PUB_NAME
152b other colors orhan pamuk random house
152c my own private idaho a smith huffington
152d the shining stephen king hatchette
152a memoirs of a geisha alan golding doubleday
- - - 5
- - - 3
- - - 6
- - - 5
8 rows returned in 0.02
seconds

You might also like