A database comprises tables and each table in case of RDBMS is called a relation.
Let us consider a sample database named University and it has two tables named Student and Marks. If a user wants to transfer a certain set of rows, insert into select statement is used along with the query. But if a user wants a whole set of rows from both tables or if a user wants to extract only a selected set of rows from both tables, joins are a perfect match to use in query.
Joins are clauses that extracts data from two tables to make a meaningful set of new data. Joins are used for a maximum of two tables only. The data that is extracted from tables forms a new table or relation that is different from previous tables that is being used for data extraction. Microsoft version of SQL supports different types of joins like – left join, right join, self join, inner join, full outer join, and cross join.
The two tables namely Student and Marks are of the same database University. If a user wants to join all rows from both tables, query must be given as –
select * from student full join marks
Table – Student
Table – Marks
We can see that tables have been joined without missing out on a single column. To extract only a few rows, we can use other joins according to convenience.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Combining aggregate and non-aggregate values in SQL using Joins and Over clause
- SQL | Join (Inner, Left, Right and Full Joins)
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- Delete statement in MS SQL Server
- SQL Server Mathematical functions (SQRT, PI, SQUARE, ROUND, CEILING & FLOOR)
- SQL Server Identity
- SQL SERVER | Conditional Statements
- SQL Server | STUFF() Function
- SQL Server | SERVERPROPERTY()
- Mean and Mode in SQL Server
- Allow only alphabets in column in SQL Server
- SQL SERVER | IN Condition
- Reverse Statement Word by Word in SQL server
- Copy tables between databases in SQL Server using Import-and-Export Wizard
- Difference between MySQL and MS SQL Server
- Comparisons between Oracle vs SQL Server
- Difference between MariaDB and MS SQL Server
- Introduction of MS SQL Server
- Select statement in MS SQL Server
- Order by in MS SQL Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.