Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Limit # of recs on inner join?




I want to limit the number of records returned by an inner join.

Suppose I have a table of Books:

book_id
title

And, a table of authors:

book_id
author_name

Now, suppose I want to get book + author, but I only want one author for books with multiple authors. Traditionally, I'd do something like:

select books.book_id, books.title, authors.author_name
from books
inner join authors on authors.book_id = books.book_id
where books.book_id = ?

This might return:

1	A Cat In The Hat	Dr. Seuss
1	A Cat In The Hat	Dr. Seuss' Partner

Instead, I just want:

1	A Cat In The Hat	Dr. Seuss

How can I limit the inner join?

Cheers,
-J




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group