Skip to content
Browse files

Add `books_with_authors` view.

  • Loading branch information...
1 parent 211ffa6 commit 444f13aec067b3177afd05dad8c096543bbd9d0a @theory committed Nov 5, 2009
Showing with 11 additions and 0 deletions.
  1. +11 −0 sql/002-books_with_authors.sql
View
11 sql/002-books_with_authors.sql
@@ -0,0 +1,11 @@
+BEGIN;
+
+CREATE VIEW books_with_authors AS
+SELECT b.isbn, b.title, b.rating,
+ array_to_string(array_agg(a.surname), ', ') as authors
+ FROM books b
+ JOIN book_author ba ON b.isbn = ba.isbn
+ JOIN authors a ON ba.author_id = a.id
+ GROUP BY b.isbn, b.title, b.rating;
+
+COMMIT;

0 comments on commit 444f13a

Please sign in to comment.
Something went wrong with that request. Please try again.