TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2220 4.26K
โœ… SQL Basics: Part-2 (SQL Commands) ๐Ÿง ๐Ÿ’พ

1๏ธโƒฃ SELECT โ€“ Pull data from a table
_Syntax:_
SELECT column1, column2 FROM table_name;


_Example:_
SELECT name, city FROM customers;


To get _everything_ use:
SELECT * FROM customers;


2๏ธโƒฃ WHERE โ€“ Filter specific rows
_Syntax:_
SELECT columns FROM table_name WHERE condition;


_Example:_
SELECT name FROM customers WHERE city = 'Delhi';


_Operators you can use:_
โ€ข =, !=, >, <, >=, <=
โ€ข LIKE (pattern match)
โ€ข BETWEEN, IN, IS NULL

3๏ธโƒฃ ORDER BY โ€“ Sort results
_Syntax:_
SELECT columns FROM table_name ORDER BY column ASC|DESC;


_Example:_
SELECT name, age FROM employees ORDER BY age DESC;


4๏ธโƒฃ LIMIT โ€“ Restrict number of results
_Syntax:_
SELECT columns FROM table_name LIMIT number;


_Example:_
SELECT * FROM products LIMIT 5;


๐Ÿ”ฅ _Quick Practice Task:_
Write a query to:
โ€ข Get top 10 highest-paid employees in 'Marketing'
โ€ข Show name, salary, and department
โ€ข Sort salary high to low:
SELECT name, salary, department
FROM employees
WHERE department = 'Marketing'
ORDER BY salary DESC
LIMIT 10;


โœ… SQL Interview QA ๐Ÿ’ผ๐Ÿง 

Q1. What does the SELECT statement do in SQL?
_Answer:_
It retrieves data from one or more columns in a table.
SELECT name, city FROM customers;


Q2. How would you fetch all the columns from a table?
_Answer:_
Use SELECT * to get every column.
SELECT * FROM orders;


Q3. Whatโ€™s the difference between WHERE and HAVING?
_Answer:_
โ€ข WHERE filters rows _before_ grouping
โ€ข HAVING filters _after_ GROUP BY
You use WHERE with raw data, HAVING with aggregated data.

Q4. Write a query to find all products with price > 500.
_Answer:_
SELECT * FROM products WHERE price > 500;


Q5. How do you sort data by two columns?
_Answer:_
Use ORDER BY col1, col2.
SELECT name, department FROM employees ORDER BY department ASC, name ASC;


Q6. What does LIMIT 1 do in a query?
_Answer:_
It returns only the _first row_ of the result.
SELECT * FROM customers ORDER BY created_at DESC LIMIT 1;


Q7. Write a query to get names of top 5 students by marks.
_Answer:_
SELECT name, marks
FROM students
ORDER BY marks DESC
LIMIT 5;


Q8. Can you use ORDER BY without WHERE?
_Answer:_
Yes. ORDER BY works independently. It sorts all data unless filtered with WHERE.

๐Ÿ’ก _Pro Tip:_
In interviews, they may ask you to _write queries live_ or explain the _output_ of a query. Stay calm, read the structure carefully, and _think in steps_.

DOUBLE TAP โค๏ธ FOR MORE
  • โค 14
  • ๐Ÿ‘ 1
More from @sqlanalyst
  1. Oct 13, 2026SQL Interview Series โ€” Part 8 ๐Ÿ“Œ Question 8: Find Customers Who Have Never Placed an Orderโ€ฆ
  2. Oct 13, 2026๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! Explorโ€ฆ
  3. Oct 12, 2026SQL Interview Series โ€” Part 6 ๐Ÿ“Œ Question 6: Find the Top 2 Highest-Paid Employees in Eachโ€ฆ
  4. Oct 12, 2026๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ? Want to builโ€ฆ
  5. Oct 9, 2026SQL Interview Series โ€” Part 5 ๐Ÿ“Œ Question 5: Find Employees Who Earn More Than Their Managโ€ฆ
  6. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
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 โ†’