Join Three Tables Sql Examples On Library Database
TO DOWNLOAD THE SAMPLE LİBRARY DATABASE CLICK
Example 1: List all student’s name,surname,book’s name and the borrow’s taken date.(three table)
1 2 3 |
Select students.name,surname,books.name,takendate from students join borrows on students.studentId = borrows.studentId join books on books.bookId = borrows.bookId |
The Result Of Query:
6308 rows were listed.
Example 2: List all student’s name,surname,book’s name,autor name and the borrow’s taken date.(four table)
1 2 3 4 |
Select students.name,students.surname,books.name,authors.name,authors.surname,takendate from students join borrows on students.studentId = borrows.studentId join books on books.bookId = borrows.bookId join authors on authors.authorId = books.authorId |
The Result Of Query:
6308 rows were listed.
Example 3:List all student’s name,surname,book name and the borrow’s taken date. Students who do not read books are also listed.
1 2 3 |
Select students.name,surname,books.name, takendate from students left join borrows on students.studentId = borrows.studentId left join books on books.bookId = borrows.bookId |
or with right join
1 2 3 |
Select students.name,surname,books.name, taken from books join borrows on books.book_id = borrows.book_id right join students on students.student_id = borrows.student_id |
Result of Both Queries:
6308 rows were listed.
will you add database examples?
sorry, i need the database for quering. I’ll wait for db. thanks bro.
Yes As soon As possible
it can be better if you can add the database. How can we get the database?
You can find the database in the site.