Class 16 of 58 • Data Manipulation & Querying (DML & DQL)

SQL SELECT Statement: Projection, Aliasing & DISTINCT

The SELECT statement is the most frequently executed and versatile command in SQL. It forms the backbone of Data Query Language (DQL), allowing developers, analysts, and applications to retrieve stored data from one or more tables, perform arithmetic, compute calculated fields, and eliminate redundant rows.


1. Basic Column Projection

To retrieve specific attributes from a table, list the column names separated by commas in the SELECT clause:

-- Query specific attributes from students
SELECT student_id, first_name, last_name, gpa
FROM students;
student_id first_name last_name gpa
1 Rahul Sharma 3.75
2 Pooja Patel 3.92
3 Aman Verma 3.85

2. Column Aliasing with the AS Keyword

Column aliases assign temporary, descriptive labels to columns or computed expressions in the query output:

-- Provide clean, presentation-ready column headings
SELECT 
    student_id AS id,
    CONCAT(first_name, ' ', last_name) AS full_name,
    gpa * 25 AS percentage_estimate
FROM students;
Space in Aliases: If an alias contains spaces, wrap it in double quotes or single quotes: AS "Student Full Name".

3. Removing Duplicate Rows with SELECT DISTINCT

When querying categorical columns (like department or city), duplicate values are returned for every row. Use DISTINCT to return only unique values:

-- Return unique list of all courses offered
SELECT DISTINCT course
FROM students;
course
BCA
B.Tech
MCA

Literal Expressions & Server Health Checks

In SQL, you can use SELECT without a FROM clause to evaluate mathematical expressions or system functions (in Oracle, use the dummy table FROM dual):

-- Evaluate math expression and server time
SELECT 
    (150 * 12) AS annual_estimate,
    CURRENT_DATE AS today,
    VERSION() AS db_version;

Now let us learn how to filter data rows using the SQL WHERE Clause!


Frequently Asked Questions (FAQ)

SELECT * retrieves every column from the table, including unneeded large TEXT/BLOB fields. This increases network bandwidth consumption, exhausts database buffer cache memory, and breaks covering index optimizations. Always name the specific columns you need.

SELECT DISTINCT inspects all projected columns in the result set and filters out any rows where all selected column values are identical.

Yes! SQL supports standard arithmetic operators (+, -, *, /) directly on numeric columns (e.g., SELECT salary, salary * 1.10 AS revised_salary FROM employees;).

Next Step in Your SQL Database Learning Path:

Proceed to the next class in sequence to build production mastery of relational database architecture.

Continue to Class 17: WHERE Clause → Previous: ← INSERT Statement | Full Syllabus


Related SQL Masterclass Lessons & Recommended Next Topics

WHERE Clause Filtering →

Filtering selected rows using conditional predicates.

ORDER BY Sorting →

Sorting output ascending or descending across multiple columns.

LIMIT & OFFSET Pagination →

Paginating large query result sets for web interfaces.

Multi-Table Joins →

Projecting columns from multiple related tables in one query.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!