Unit 5.6: Introduction to SQL (Structured Query Language)

1. Introduction

In the modern business landscape, data is often called the “new oil” – a valuable asset that can drive strategy and growth. However, raw data is useless unless it can be accessed, managed, and analyzed. This is where the Structured Query Language (SQL) comes in. SQL is the standard language used to communicate with and manage data stored in a Relational Database Management System (RDBMS).

For business professionals, understanding the basics of SQL is not about becoming a programmer; it’s about understanding how to ask questions of your data. It is the bridge between complex databases and actionable business insights, enabling managers in every department—from Finance to HR—to make informed, data-driven decisions.


2. Understanding SQL

What is SQL?

SQL (Structured Query Language) is a domain-specific language designed for managing data held in a relational database. It allows you to perform a wide range of tasks, including:

  • Querying Data: Retrieving specific information from a database.
  • Manipulating Data: Inserting, updating, and deleting records.
  • Defining Data: Creating and modifying the structure of the database itself (e.g., creating tables).
  • Controlling Access: Setting permissions for users to access and manipulate data.

SQL is a declarative language, which means you tell the database what you want to do, and the database system figures out how to do it. This makes it relatively easy to learn for non-technical users.

Core SQL Commands for Business Users

While SQL has a vast command set, business professionals typically interact with a few core commands. These are often grouped into categories. The most important for business analysis is the Data Manipulation Language (DML) and the SELECT query.

Data Retrieval (SELECT)

This is the most frequently used command in business. It is used to retrieve data from one or more tables.

  • SELECT: Specifies the columns (data fields) you want to retrieve.
  • FROM: Specifies the table you are pulling the data from.
  • WHERE: Filters the records based on a specific condition.

Simple Example: Imagine a Customers table. To get the names and email addresses of all customers from Kathmandu:

SELECT CustomerName, Email
FROM Customers
WHERE City = 'Kathmandu';

Data Manipulation (INSERT, UPDATE, DELETE)

These commands are used to manage the data within the tables.

  • INSERT INTO: Adds a new row of data into a table.
    • Business Use: Adding a new employee to the HR database or a new sale to the transactions table.
  • UPDATE: Modifies existing records in a table.
    • Business Use: Changing a customer’s shipping address or updating a product’s price.
  • DELETE: Removes records from a table.
    • Business Use: Removing a discontinued product from the inventory list.

3. Business Applications of SQL Across Functions

SQL is not just for the IT department. Its power is realized when applied across all core business functions.

Finance and Accounting

The finance department relies on accurate and timely data for reporting and analysis. SQL is used to:

  • Generate Financial Reports: Write queries to pull data for income statements, balance sheets, and cash flow statements for specific periods.
  • Transaction Auditing: Isolate and review specific transactions, such as all payments over NPR 1,000,000 or all transactions with a specific vendor.
  • Sales Analysis: Aggregate sales data to analyze revenue by product, region, or salesperson.
    • Example Query: SELECT SUM(SaleAmount) FROM Sales WHERE SaleDate BETWEEN '2023-01-01' AND '2023-03-31'; (Calculates total sales for Q1 2023).

Marketing

Marketing teams use SQL to understand customer behaviour and personalize campaigns.

  • Customer Segmentation: Identify specific customer groups based on purchase history, location, or engagement.
    • Example Query: SELECT Email FROM Customers WHERE LastPurchaseDate < '2023-01-01' AND City = 'Pokhara'; (Finds emails of customers in Pokhara who haven’t purchased this year, for a re-engagement campaign).
  • Campaign Performance Analysis: Track the effectiveness of marketing campaigns by querying sales data linked to specific promotion codes.
  • Personalization: Retrieve a customer’s browsing and purchase history to power personalized product recommendations on an e-commerce site.

Human Resources (HR)

HR departments manage vast amounts of employee data, from payroll to performance.

  • Employee Data Management: Quickly retrieve employee information, such as contact details, department, or start date.
  • Payroll Processing: Run queries to calculate salaries, bonuses, and deductions based on employee roles, hours worked, and tax information.
  • Performance Reporting: Identify top-performing employees or departments by analyzing performance review scores or sales data.
    • Example Query: SELECT EmployeeName, Department FROM Employees WHERE YearsOfService > 10; (Finds all employees with over 10 years of service for an awards program).

Operations and Supply Chain

Efficient operations depend on real-time data about inventory, orders, and suppliers.

  • Inventory Management: Check stock levels, identify low-stock items, and track product movement.
    • Example Query: SELECT ProductName, StockQuantity FROM Products WHERE StockQuantity < 50; (Lists all products that need to be reordered).
  • Order Tracking: Monitor the status of customer orders from placement to delivery.
  • Supplier Management: Analyze supplier performance by querying data on delivery times, costs, and product quality.

4. Real-World Examples from Nepal

SQL is the invisible engine powering many of the digital services we use daily in Nepal.

Example 1: Digital Wallets (eSewa, Khalti)

Digital wallets handle millions of transactions daily. Their entire system is built on robust databases.

  • How SQL is used: When you open your eSewa app to view your transaction history, a SELECT query is sent to the database in the background. This query asks the database to retrieve all transactions linked to your User ID.
  • Sample Query (Conceptual):
    SELECT TransactionType, Amount, TransactionDate, MerchantName
    FROM Transactions
    WHERE UserID = '98XXXXXXXX'
    ORDER BY TransactionDate DESC;
    

    This simple command fetches your transaction details and sorts them by the most recent, allowing the app to display your statement accurately.

Example 2: E-commerce Platforms (Daraz Nepal)

Daraz manages a massive catalog of products, sellers, and customer orders. SQL is essential for managing this complexity.

  • How SQL is used: When you search for a “red t-shirt under NPR 1000” on Daraz, the website translates your search into an SQL query. This query filters millions of products to show you only the ones that match your criteria. When a product is sold, an UPDATE query reduces the stock quantity in the inventory table.
  • Sample Query (Conceptual):
    SELECT ProductName, Price, SellerName
    FROM Products
    WHERE Category = 'T-shirt' AND Color = 'Red' AND Price < 1000;
    

Example 3: Banking Sector (Nabil Bank, NIC Asia Bank)

The core banking system (CBS) of any bank is a large, secure database. Every deposit, withdrawal, and loan is a record in a database table.

  • How SQL is used: When you use a bank’s mobile app to check your account balance, the app sends a secure request that executes a simple SQL query.
  • Sample Query (Conceptual):
    SELECT AccountBalance
    FROM Accounts
    WHERE AccountNumber = 'YOUR_ACCOUNT_NUMBER';
    

    This ensures that you receive real-time, accurate information about your finances. SQL also helps banks generate reports for regulatory bodies like Nepal Rastra Bank.


5. Key Takeaways

  • SQL is the universal language for interacting with relational databases.
  • It empowers business users to ask questions of their data and retrieve specific information for decision-making.
  • The SELECT statement is the most critical command for business analysis, used for fetching and filtering data.
  • SQL is applied across all business functions: Finance, Marketing, HR, and Operations, making it a versatile tool for any manager.
  • Many services used daily in Nepal, from digital payments to e-commerce and banking, rely heavily on SQL to manage their data.

6. Review Questions

  1. What does SQL stand for, and why is it considered a “declarative” language?
  2. Provide one practical example of how the HR department and the Operations department at a company like Daraz might use an SQL query.
  3. Explain the difference between the UPDATE and INSERT commands in SQL, giving a business scenario for each.
  4. When you use the eSewa app to pay a utility bill (e.g., your internet bill), what kind of SQL operations do you think are happening in the background? (Hint: Think about your balance and the transaction record).