简体   繁体   中英

Getting data from three tables. Should I join them?

I have three tables I'm trying to use.

Author (AuthorID, Lname, Fname)

Book Author (ISBN, AuthorID)

Books (ISBN, Title)

Need to display it like this:

 AUTH LNAME     FNAME     TITLE
 ---- -----------------------------------------------
 S101 Smith     Roger     TRAVELING TO FRANCE         
 S101 Smith     Roger     HOW TO BAKE A CAKE
 J101 Wilson    Kenny     ADVENTURES OF THE MAN              
 P101 Peters    Lemon     SCIENCE AND MATH 
 S101 Fogo      Baker     SCIENCE AND MATH

The closest I can is this:

 SELECT authorid, title
 FROM bookauthor, books
 WHERE book author.isbn = books.isbn

Which gives me:

 AUTH TITLE                        
 ---- ------------------------------
 S101 TRAVELING TO FRANCE          
 S101 HOW TO BAKE A CAKE         
 J101 ADVENTURES OF THE MAN             
 P101 SCIENCE AND MATH
 S101 SCIENCE AND MATH

But that leaves out the first and last name, which I'm trying to include.

I looked at other questions regarding joining tables but I can't seem to apply it to my script. Beginner at Oracle SQL so any help is appreciated.

You could do...

select author id, Lname, Fname , title from author, book author,books 
where author.author id = booksauthor.authorid 
and booksauthor.ISBN = booksauthor.isbn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM