TGViewer
Data Science & Machine Learning Data Science & Machine Learning @datasciencefun · 77.8K subscribers
Post #4626 1.42K
you tell the database:

What data you want

You generally don't tell the database exactly how to retrieve it internally.

The database's query optimizer determines an efficient execution strategy.

This is one reason SQL is called a declarative language.

🔹 11. SQL Keywords

SQL uses keywords such as:

SELECT

FROM

WHERE

GROUP BY

ORDER BY

HAVING

JOIN

These keywords define the structure of the query.

For example:

SELECT name
FROM customers;


Here:

SELECT → What to retrieve

FROM → Where to retrieve it from

🔹 12. SQL Case Sensitivity

SQL keywords are commonly written in uppercase:

SELECT

FROM

WHERE

This improves readability.

For example:

SELECT customer_id, name
FROM customers;


is easier to read than:

select customer_id,name from customers;


Most SQL database systems treat keywords as case-insensitive, although behavior regarding identifiers such as table and column names can vary by database system and configuration.

Recommended style:

Use:

UPPERCASE for SQL keywords

lowercase or snake_case for column/table names

🔹 13. Column Aliases

You can temporarily give a column a different name using AS.

Example:

SELECT
name AS customer_name
FROM customers;


The result will display:

customer_name
Alice
Bob
Carol


The original column name in the database is not changed.

The alias only changes how the result is displayed.

🔹 14. Aliases Without AS

In many SQL systems, you can also write:

SELECT
name customer_name
FROM customers;


However, using AS is generally clearer:

SELECT
name AS customer_name
FROM customers;


🔹 15. Calculations in SELECT

SQL can perform calculations.

Suppose we have:

price

quantity

We can calculate total sales:

SELECT
price,
quantity,
price * quantity AS total_amount
FROM orders;


This creates a calculated column:

total_amount = price × quantity

This ability becomes extremely useful in Data Analytics.

🔹 16. Using SELECT with Expressions

You can perform various calculations.

Example:

SELECT
salary,
salary * 12 AS annual_salary
FROM employees;


If monthly salary is:

₹50,000

then:

annual_salary = ₹600,000

The original database isn't modified.

The calculation is performed when the query runs.

🔹 17. Selecting Constants

SQL can also return constant values.

Example:

SELECT
'Data Science' AS course;


Result:

course
Data Science


You can also use numbers:

SELECT
2026 AS year;


Result:

year
2026


This becomes useful when constructing analytical datasets.

🔹 18. DISTINCT

DISTINCT is part of the roadmap and we'll study it properly later.

For now, understand its basic purpose:

It returns unique values.

Suppose:

city

Pune

Mumbai

Pune

Delhi

Mumbai

Query:

SELECT DISTINCT city
FROM customers;


Result:

Pune
Mumbai
Delhi


Duplicate values are removed from the result.

🔹 19. SELECT DISTINCT on Multiple Columns

You can use multiple columns:

SELECT DISTINCT city, department
FROM employees;


Important:

DISTINCT applies to the combination of selected columns.

So if two rows have the same city but different departments, they are considered different combinations.

🔹 20. SQL Query Example

Imagine an orders table:
  • ❤ 2
More from @datasciencefun
  1. Oct 2, 2026Data Visualisation tips for beginners
  2. Sep 29, 2026𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗟𝗲𝗮𝗿𝗻 𝗔𝗜 𝗶𝗻 𝟮𝟬𝟮𝟲🚀 ​ Explore 6 free resource…
  3. Sep 28, 2026🔹 Real-World Data Science Example Suppose you are analyzing sales data. You want to ident…
  4. Sep 28, 2026🚀 Data Science Roadmap 2026 📍 Phase 3: SQL for Data Science 📖 Topic 3 — ORDER BY ORDER…
  5. Sep 28, 2026🎓 𝗛𝗔𝗥𝗩𝗔𝗥𝗗 𝗨𝗡𝗜𝗩𝗘𝗥𝗦𝗜𝗧𝗬 𝗙𝗥𝗘𝗘 𝗢𝗡𝗟𝗜𝗡𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 😍 Dreaming of…
  6. Sep 27, 2026Complete Data Analytics Mastery: From Basics to Advanced 🚀 Begin your Data Analytics jour…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →