Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    1 page views
  •   0 video views

#090 How to return order data with customer details in Azure SQL

How to return order data, including customer details in existing Query (SELECT) in Azure SQL/SQL Server Data Manipulation Language (DML)

This T-SQL code performs a query using the INNER JOIN clause to combine data from two tables, Orders and Customers. The query returns order-specific information, including the order ID, order date, and associated customer name. Let's explain each part of the code:

SELECT Orders.OrderID, Orders.OrderDate, Customers.Name
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
SELECT
  1. Orders.OrderID, Orders.OrderDate, Customers.Name

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • Orders.OrderID, Orders.OrderDate, Customers.Name: These are the columns that will be returned in the query. These are the specific columns from the Orders and Customers tables that we want to include in the results.
  2. FROM:

    • Indicates the table from which the data will be selected.
    • Orders: This is the name of the table from which the data will be extracted. In this case, we're selecting data from the Orders table.
  3. INNER JOIN Customers
  4. ON Orders.CustomerID = Customers.CustomerID:

    • INNER JOIN: This is a clause that combines records from both tables based on a specified condition. Returns only those records that match in both tables.
    • Customers: This is the name of the table that will be combined with the Orders table.
    • ON Orders.CustomerID = Customers.CustomerID
    • : Specifies the join condition, indicating that the records in the Customers table will be combined with the records in the Orders table where the values in the CustomerID column are the same.
Therefore, the code returns the OrderID

and OrderDate columns from the Orders table, along with the Name column from the Customers table, for records where there is a match between the tables in the CustomerID columns. This query is useful when you need order information along with the associated customer details.

This content contains
  • Content Imagem
  • Language Portuguese
  • Duration
  • Subtitles Não

  • Reading time 1 min 28 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now