The Sql Join Clause

The Sql Join Clause

  • Sql Join Clause is used to combine two or more tables.
  • To Combine tables we use common columns of tables.
  • The Join Clause makes a artificial relation on tables(not realy, effective only at the query)
  • We can use where clause instead of join (not for left join, right join,or full join)
  • We can use Inner Join instead of join. They are same.

The Join has different types: Left Join, Right Join, Full Join

Syntax for Join Clause

Select columnNames from Table1 join Table2 on Table1.relationColumn= Table2.relationColumn

or with where clause

Select columnNames from Table1, Table2 where Table1.relationColumn= Table2.relationColumn

TO DOWNLOAD THE SAMPLE LİBRARY DATABASE CLICK

The Sql Join Clause Example on Library Database

Sample 1: List all student’s name,surname and the borrow’s taken date.(two tables)

or

Sample 2: List all student’s name,surname,book’s name and the borrow’s taken date.(three table)

or

Note: If we have same column names at different tables,  then we must write the column’s names with their table’s name.

Sample 3: List all student’s name,surname,book’s name,autor name  and the borrow’s taken date.

Select students.name as studentName,students.surname,books.name as BookName,takenDate, authors.name as AuthorName,authors.surname as AuthorSurname from students join borrows on students.studentId = borrows.studentId join books on books.bookId = borrows.bookId join authors on authors.authorId = books.authorId

Sample 4: List all student’s name,surname and the borrow’s taken date, where student name Jefferson.

YOU MAY WANT TO SEE OUR ALL EXAMPLES PAGE, THEN CLICK HERE

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: