MySQL Tutorials
Estimated reading: 4 minutes 364 views

2️⃣ MySQL SQL Fundamentals – Learn Core SQL for MySQL (2025 Guide)


Introduction – Why SQL Matters in MySQL?

Structured Query Language (SQL) is the standard language for interacting with relational databases like MySQL. Whether you’re querying user data, filtering records, or performing aggregations, mastering SQL is essential for database management, reporting, and back-end development.

In this guide, you’ll learn:

  • The foundational SQL commands used in MySQL
  • How to retrieve, filter, and sort data effectively
  • Logical and comparison operators for complex queries
  • Aggregate functions, aliases, and conditional logic

Topics Covered

Topic Description
MySQL OverviewCore concepts of SQL in the MySQL environment
MySQL SELECT StatementRetrieve data from tables
MySQL WHERE ClauseFilter records using conditions
MySQL Logical OperatorsCombine conditions with AND, OR, NOT
MySQL Comparison OperatorsUse IN, BETWEEN, LIKE, IS NULL, etc.
MySQL Sorting & LimitingSort results and restrict output size
MySQL Aliases & CommentsRename columns/tables and add query comments
MySQL CASE, ANY, ALL, EXISTSImplement advanced condition handling
MySQL Aggregate FunctionsPerform data calculations (SUM, COUNT, etc.)

MySQL SQL Overview

SQL (Structured Query Language) is used to create, read, update, and delete (CRUD) data in MySQL databases. The SQL syntax in MySQL supports both ANSI standard SQL and MySQL-specific extensions.

Types of SQL Statements:

  • Data Query Language (DQL): SELECT
  • Data Definition Language (DDL): CREATE, ALTER, DROP
  • Data Manipulation Language (DML): INSERT, UPDATE, DELETE
  • Data Control Language (DCL): GRANT, REVOKE

MySQL SELECT Statement

The SELECT statement fetches data from one or more tables.

SELECT name, age FROM users;

Key Features:

  • Select all columns with *
  • Combine with WHERE, ORDER BY, GROUP BY, etc.
  • Supports joins and subqueries

MySQL WHERE Clause

Used to filter rows based on a condition.

SELECT * FROM employees WHERE department = 'Sales';

Use Case: Display records that meet certain criteria before applying sorting or aggregation.


MySQL Logical Operators (AND, OR, NOT)

Used within WHERE to build complex filtering logic.

SELECT * FROM orders WHERE amount > 500 AND status = 'confirmed';

Operators:

  • AND: All conditions must be true
  • OR: Any condition must be true
  • NOT: Negate a condition

MySQL Comparison Operators

Allow you to test values with greater flexibility:

OperatorPurposeExample
INMatches any value in a listWHERE country IN ('US', 'UK')
BETWEENChecks a rangeWHERE age BETWEEN 18 AND 30
LIKEPattern matchingWHERE name LIKE 'A%'
IS NULLChecks for null valuesWHERE email IS NULL
NOT NULLChecks for non-nullWHERE phone IS NOT NULL

MySQL Sorting & Limiting

ORDER BY

Sort results in ascending or descending order.

SELECT * FROM products ORDER BY price DESC;

LIMIT

Limit number of records returned.

SELECT * FROM products LIMIT 5;

DISTINCT

Remove duplicate values in result set.

SELECT DISTINCT city FROM customers;

MySQL Aliases & Comments

Aliases

Use AS to rename columns or tables for clarity.

SELECT first_name AS Name FROM users;

Comments

Add inline documentation to queries:

-- This fetches all customers from New York
SELECT * FROM customers WHERE city = 'New York';

MySQL CASE, ANY, ALL, EXISTS

CASE

Conditional logic inside queries.

SELECT name,
       CASE 
         WHEN salary > 5000 THEN 'High'
         ELSE 'Low'
       END AS SalaryCategory
FROM employees;

EXISTS

Check if subquery returns rows.

SELECT * FROM employees
WHERE EXISTS (SELECT * FROM departments WHERE dept_id = employees.dept_id);

MySQL Aggregate Functions

FunctionDescriptionExample
COUNT()Counts number of rowsSELECT COUNT(*) FROM orders;
SUM()Adds values in a columnSELECT SUM(amount) FROM orders;
AVG()Average of column valuesSELECT AVG(score) FROM students;
MIN()Minimum valueSELECT MIN(age) FROM users;
MAX()Maximum valueSELECT MAX(price) FROM products;

Summary – Recap & Next Steps

SQL is the foundation of working with MySQL databases. It enables powerful data retrieval, conditional filtering, sorting, and summarizing of data for applications and reports. Learning these core SQL commands is the first step in becoming proficient in database operations.

Key Takeaways:

  • SELECT, WHERE, and logical operators are essential for queries
  • Aggregation and sorting add analysis power
  • SQL is the language behind MySQL’s power

Real-World Relevance:
From fetching customer data to creating dashboards or generating invoices, SQL fundamentals are essential in every backend, analytics, and data role.


FAQs – MySQL SQL Fundamentals

What is SQL in MySQL?
SQL is the standard language for managing and manipulating data stored in MySQL databases.

What is the most used SQL command?
SELECT is the most commonly used command for retrieving data.

What is the difference between WHERE and HAVING?
WHERE filters rows before grouping, while HAVING filters after aggregation.

Can I use logical and comparison operators together?
Yes, for example: WHERE price > 100 AND category IN ('Books', 'Electronics')

What are aggregate functions used for?
They compute summary values like totals, averages, or counts from a column.


Share Now :
Share

2️⃣ 🔎 MySQL SQL Fundamentals

Or Copy Link

CONTENTS
Scroll to Top