What is an inner join in SQL

Summary: in this tutorial, you will learn how to use the SQL Server clause to query data from multiple tables.

Introduction to SQL Server

The inner join is one of the most commonly used joins in SQL Server. The inner join clause allows you to query data from two or more related tables.

See the following and tables:

The following statement retrieves the product information from the table:

The query returned only a list of category identification numbers, not the category names. To include the category names in the result set, you use the clause as follows:

In this query, the inner join clause matches rows from both and tables. If a row in the table has the same value in the column as a row in the table, the query combines the values of columns specified in the select list into a new row and includes that new row in the result set.

SQL Server syntax

The following shows the syntax of the SQL Server clause:

In this syntax, the query retrieved data from both T1 and T2 tables:

  • First, specify the main table (T1) in the clause
  • Second, specify the second table in the clause (T2) and a join predicate. Only rows that cause the join predicate to evaluate to are included in the result set.

The clause compares each row of the table T1 with rows of table T2 to find all pairs of rows that satisfy the join predicate. If the join predicate evaluates to , the column values of the matching rows of T1 and T2 are combined into a new row and included in the result set.

The following table illustrates the inner join of two tables T1 (1,2,3) and T2 (A,B,C). The result includes rows: (2,A) and (3,B) as they have the same patterns.

Note that the keyword is optional, you can skip it as shown in the following query:

More SQL Server inner join examples

See the following , , and tables:

The following statement uses two clauses to query data from the three tables:

In this tutorial, you have learned how to use the SQL Server clause to query data from multiple tables.

  • Was this tutorial helpful ?
  • YesNo
    product_name,
    list_price,
    category_id
    production.products
    product_nameDESC;
    product_name,
    category_name,
    list_price
    production.productsp
INNERJOINproduction.categoriescONc.category_id=p.category_id
    product_nameDESC;
    select_list
    T1
INNERJOINT2ONjoin_predicate;
    select_list
    T1
JOINT2ONjoin_predicate;
    product_name,
    category_name,
    brand_name,
    list_price
    production.productsp
INNERJOINproduction.categoriescONc.category_id=p.category_id
INNERJOINproduction.brandsbONb.brand_id=p.brand_id
    product_nameDESC;