14 Apr 2019

MSSQL Join inner left right full cross union

sql2

We used the Sql Server Management Studio (SSMS) in MSSQL and explored the different kind of joins: inner-join, left-join, right-join, full-join, cross-join and union. inner join selects records that have matching values in both tables, left join returns all records from the left table (“left” means the left table name in the query. the first table name appearing in the query), and the matched records from the right table (right table name in the query). The result is NULL from the right side, if there is no match. right-join returns all records from the right table , and the matched records from the left table. The result is NULL from the left side, when there is no match. full-join return all records when there is a match in either left or right  table records. Union operator is used to combine the result-set of two or more SELECT statements. Cross-join produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table (This kind of result is called as Cartesian Product). and finally we saw how to insert multiple rows to a table using single query of insert + select

joins

More topics covered:

  • Working with SSMS
  • Creating foreign key in SSMS designer
  • Displaying two tables in one query
  • SSMS “prevent saving changes…” option

Links:

Leave a comment

Design a site like this with WordPress.com
Get started