Search code examples
javasqlinner-join

Display Inner Join Results


I have to write a query to

Select a specific author and list all books for that author. Include each book’s title, year and ISBN.

I have written the query statement as such

resultSet = statement.executeQuery("SELECT FirstName, LastName FROM Authors    "
                        + "INNER JOIN AuthorISBN ON Authors.AuthorID =   AuthorISBN.AuthorID "
                        + "INNER JOIN Titles ON AuthorISBN.ISBN = Titles.ISBN"); 

The results display and sort based on author name, but how do I also have the table display the book title the year and the ISBN? Right now it only displays the authors first name and last name.


Solution

  • Add the columns you want in the select clause like this :

    SELECT Authors.FirstName, Authors.LastName, Titles.year, Titles.ISBN
    FROM Authors 
    INNER JOIN AuthorISBN ON Authors.AuthorID = AuthorISBN.AuthorID 
    INNER JOIN Titles ON AuthorISBN.ISBN = Titles.ISBN