Updated March 29, 2023
Introduction to T SQL Join
T-SQL stands for transact–Structured Query Language which is a supplement of SQL language. It can add the procedural programming feature in SQL hence it can able to define variables, control statements, creating functions by calling them in a particular event which all can be done in T-SQL. It will ensure data consistency, it can support the exception data handling, it can make a code modular while working with the transaction. It helps in maintaining batches that can be set of SQL commands which we want to execute on a single go by using the go command.
Overview of T-SQL join
SQL is the structured query language and it has been used in the usual database language in which it can be used by all the products of the Relational database management system, various vendors of RDBMS product has extended the SQL database language in their own products, so T-SQL is an extension of SQL which can be the Microsoft’s product. It can work with various functions, procedures, indexes, and also transactions while working with the transaction it allows to create the number of procedures and functions.
The T-SQL has been utilized to give a set of tools for the development of transactional databases, the JOIN clause has been used to merge records from two or more tables within a database, with the help of join we can retrieve the data from the table which have common field and also we can join the tables which also does not have the common fields. The inner join can merge two tables and we can retrieve common fields from that, the left join can give the common data from one table even though there are no common fields in another table, the right join can also provide the data which is common in both with all records from the right table, and full join can get all the rows from both the tables.
T SQL Join Table
The join is the clause that can provide us the common records from two or more tables in any database, we can say that the ‘JOIN’ keyword can merge rows from two tables with the help of common values from both the tables. The join can indicate the relationship between the tables, it can also show how the SQL server can utilize data from one table for selecting data from other tables.
If we have two tables then by using select statement with where condition we can able to retrieve data from both the table which we required, in this way we can able to join the two tables. Let us see the joining of a table in detail.
Employee Table:
Order Table:
Then we can able to join these tables with the help of the SELECT statement,
“SELECT ID, Name, Age, Amount FROM Employee, Order WHERE Employee.ID = Order.EMP_ID;”
It will return tables such as,
In this way we can get the data that we require by using the SELECT statement, we can also say that the join can carry out in the WHERE clause, in which we can also able to use the operators (=, <, >, < >, <=, >=, !=, BETWEEN, LIKE, and NOT) to join the tables in which equal(=) is the most usually used in the queries for putting the conditions.
T-SQL join Types
- INNER join:
This join can merge records from two tables wherever there are common values in the rows which are common in both the table, in which we can say that it gives back the rows which are the same in both the tables.
Syntax:
- LEFT join:
This join can return all rows from the left table with matched rows from the right table, if there is no matching with the right table then it will return all rows from the left table, in some databases, it is also called as left outer join.
Syntax:
- RIGHT join:
This join can return all rows from the right table with matching rows from the left table, if there is no matching in a left table then it will return all records from the right table, in some databases it is also called as right outer join.
Syntax:
- FULL Outer join:
This join there is no need to have matching in between two tables it will returns all rows from the left table and all rows from the right table, in which full join and full outer join both are similar.
Syntax:
Server join example
By using join, we can get the data from one or more tables which can have related columns and also as per the requirement or need, in which it has four different types of joins, let us see the example of join in SQL server.
INNER JOIN:
This join can return the rows from both tables in which the ‘where’ condition is true, let us see the syntax,
Let us discuss two tables to signify the above syntax,
Student Table,
Fees table:
Let us see the query to get data from the above two tables by using an INNER join.
The above query will return the below table,
In which we can able to give information to students that who have already paid their fees in which we have used the ‘Admission’ column same as in both tables, in the above example we have used two tables that is ‘Student’ and ‘Fees’ table so we have to use ‘INNER’ join for that we have used the ‘SELECT’ statement and try to retrieve data from ‘Admission’, ‘FName’, ‘LName’ from Student table and ‘Amount_paid’ record from fees table so we get the information in the resultant table.
Conclusion
In this article we conclude that the T-SQL is an extension for SQL which can add procedural programming features in the SQL, we have also discussed the overviews of T-SQL, T-SQL join tables, and also types of it, so this article will help to understand the concept of the T-SQL in details.
Recommended Articles
This is a guide to T SQL Join. Here we discuss the Introduction, overviews, T SQL Join Table, Server join example, T-SQL join Types. You may also have a look at the following articles to learn more –