SQL for Beginners: Writing Your First Query


Posted on: Fri Jun 06 2025

Author: Ignatius Emeka

What Is SQL?

SQL is a language used to interact with relational databases, which store data in tables with rows and columns. You can use SQL to:

  • Retrieve data (e.g., find customer names).
  • Insert new data.
  • Update existing records.
  • Delete unwanted data.

Why Learn SQL? It’s in high demand for roles like data analyst, business intelligence developer, and backend engineer. SQL’s simplicity makes it perfect for beginners.

Understanding SQL Queries

A query is an SQL command to interact with a database. The most common query is SELECT, which retrieves data from tables.

SELECT column_name FROM table_name WHERE condition;

  • SELECT: Specifies the columns to retrieve.
  • FROM: Names the table.
  • WHERE: Filters rows based on conditions.

Example 1: Your First Query

Let’s query a table called employees with columns id, name, and salary. To get all employee names:

SELECT name FROM employees;

Explanation:

  • SELECT name: Retrieves only the name column.
  • FROM employees: Targets the employees table.
  • Output: A list of employee names (e.g., “Alice,” “Bob”).

Example 2: Filtering Data

To find employees with a salary above 50,000:

SELECT name, salary FROM employees WHERE salary > 50000;

Explanation:

  • SELECT name, salary: Retrieves two columns.
  • WHERE salary > 50000: Filters for employees with salaries above 50,000.
  • Output: Names and salaries of qualifying employees (e.g., “Alice, 60000”).

Example 3: Sorting Results

To list employees alphabetically by name:

SELECT name FROM employees ORDER BY name ASC;

Explanation:

  • ORDER BY name ASC: Sorts results in ascending order (A-Z).
  • Output: Names like “Alice,” “Bob,” “Charlie.”

Example 4: Combining Conditions

To find employees named “Alice” with a salary above 50,000:

SELECT name, salary FROM employees WHERE name = 'Alice' AND salary > 50000;

Explanation:

  • WHERE name = 'Alice' AND salary > 50000: Combines conditions with AND.
  • Output: Only “Alice” if her salary exceeds 50,000.

Putting It Together: A Practical Example

Let’s create a program to query a products table (columns: product_id, product_name, price) and find products priced between 20 and 100.

SELECT product_name, price
FROM products
WHERE price BETWEEN 20 AND 100
ORDER BY price ASC;

How It Works:

  • SELECT product_name, price: Retrieves product names and prices.
  • WHERE price BETWEEN 20 AND 100: Filters for prices in the range.
  • ORDER BY price ASC: Sorts results by price (lowest to highest).
  • Sample Output:

product_name | price
--------------|-------
Book | 25
Headphones | 80

How to Execute the Code

To try these SQL queries:

  1. Install a Database Tool:
    • Local: Download MySQL or SQLite. MySQL Community Server is free at mysql.com. SQLite is lightweight and requires no setup.
    • Online: Use platforms like DB Fiddle or SQL Fiddle.
  2. Set Up a Database:
    • In MySQL, create a database: CREATE DATABASE store; USE store;
    • Create a products table:

CREATE TABLE products (
product_id INT,
product_name VARCHAR(50),
price DECIMAL(10,2)
);

  • Insert sample data:

INSERT INTO products VALUES
(1, 'Book', 25.00),
(2, 'Headphones', 80.00),
(3, 'Laptop', 1200.00);

  1. Run the Query:
    • In MySQL, paste the practical example query into the command-line client or a GUI like MySQL Workbench.
    • In DB Fiddle, select MySQL, paste the table creation, data insertion, and query, then click “Run.”
  2. Test It: Verify the output matches the sample (e.g., “Book, 25” and “Headphones, 80”).
  3. Troubleshooting:
    • Check syntax (e.g., semicolons, correct table/column names).
    • Ensure the table has data.
    • Join PalmTechnIQ’s community for support if you hit errors.

Why Learn SQL?

SQL is foundational for data-driven roles. It powers:

  • Data Analysis: Extract insights from large datasets.
  • Business Intelligence: Generate reports for decision-making.
  • Backend Development: Manage data for apps.

Mastering SQL opens doors to careers in data science, analytics, and more.

How PalmTechnIQ Helps

PalmTechnIQ’s SQL courses are designed for all levels:

  • Real-time projects: Build dashboards or analyze datasets.
  • Certificates: Validate your skills for employers.
  • Mentorship: Learn from data experts.
  • Community: Connect with peers for collaboration.

Start Your SQL Journey

SQL is your gateway to a data-driven career. Visit PalmTechnIQ to enroll in our SQL for Beginners course and master querying in 2025.

sqlsql querieslearn sqldata scienceprogramming for beginnersdata analysisdatabase managementonline learningtech educationcareer in techpalmtechniqdigital skills

Connect with us on:

Explore PalmTechnIQ courses at: Courses

PalmTechnIQ
PalmTechnIQ is an educational platform that offers a wide range of courses and resources in various fields such as technology, business, arts, and more. Our mission is to provide accessible and high-quality education to learners worldwide.
Subscribe To Our Newsletter
Powered by ISCE
2024 PalmTechnIQ. All Rights Reserved.