Notes
Chapter 13: Simple SELECT Statements

1. SELECT Statement Basics

The SELECT statement in Microsoft SQL Server is the foundation of retrieving data from one or more tables. It allows you to specify which columns you want to retrieve and which tables you want to query.

Basic SELECT Syntax:

Example :

Basic SELECT statement
SELECT FirstName, LastName
FROM Employees;

In this example, the SELECT statement retrieves the "FirstName" and "LastName" columns from the "Employees" table.

2. Filtering Data with WHERE

The WHERE clause is used with the SELECT statement to filter data based on specified conditions.

Using WHERE:

Example :

Using WHERE to filter data
SELECT ProductName,Price
FROM Products
WHERE Price > 50;

This query retrieves the names and prices of products with prices greater than 50.

3. Real-world Use Cases of SELECT

E-commerce System:
  • Product Listings: Use SELECT to display a list of products available for purchase on the website.
  • Order History: Retrieve order history for a specific customer to show past purchases.
Inventory Management System:
  • Inventory Tracking: Use SELECT to monitor current stock levels and identify items that need restocking.
  • Supplier Reports: Generate reports on the products supplied by each vendor.

4. Key Takeaways

  • The SELECT statement is used to retrieve data from one or more tables.
  • The WHERE clause is used to filter data based on specified conditions.
  • Real-world scenarios often involve using SELECT to fetch data for various purposes, such as displaying information to users or generating reports.

5. Exercise Questions

  1. Retrieve the first name and last name of all employees from the "Employees" table.
  2. List the product names and their corresponding prices from the "Products" table.
  3. Display the order IDs and order dates for all orders placed by customer ID 123.
  4. In a library database, select the titles of all books written by a specific author.
  5. Retrieve a list of products from the "Inventory" table with quantities less than 10.
  6. Explain how you would use the WHERE clause to filter data from a "Sales" table to find all sales made in a specific month.
Data Insertion Techniques

The INSERT statement in Microsoft SQL Server is used to add new rows to a table. There are several variations of the INSERT statement to accommodate different data insertion scenarios.

Read More
Joins

In Microsoft SQL Server, a JOIN operation combines rows from two or more tables based on a related column between them. It is a fundamental concept in database management that allows you to retrieve and analyze data from multiple tables.

Read More