DSPython Logo DSPython

SQL Basic Queries

Master fundamental SQL operations: SELECT, WHERE, ORDER BY, DISTINCT, and JOINs.

SQL Basics Beginner 30 min

πŸ” Topic 1: SELECT Statement Basics

The SELECT statement retrieves data from one or more columns of a table. Projection means choosing specific columns to return.

πŸ“ Basic SELECT Syntax:

  • SELECT * β€” all columns
  • SELECT col1, col2 FROM table β€” specific columns
  • SELECT DISTINCT col FROM table β€” unique values

🎯 Topic 2: WHERE Clause β€” Filtering Data

Use WHERE to filter rows. It runs before GROUP BY/HAVING and cannot use aggregate functions.

πŸ” Common WHERE Operators:

  • =, !=, <, >, <=, >=
  • LIKE for pattern matching, IN() for list membership
  • BETWEEN, IS NULL, boolean AND/OR/NOT

πŸ“Š Topic 3: ORDER BY & LIMIT

ORDER BY sorts results. Use ASC (default) or DESC. LIMIT restricts number of returned rows.

πŸ”— Topic 4: JOIN Operations

JOINs combine rows from two tables. Use matching keys to relate rows. INNER returns matches; LEFT returns all left rows; RIGHT/FULL depend on DB support.

πŸ”„ JOIN Examples:

SELECT e.FirstName, e.LastName, p.ProjectName
FROM Employees e
INNER JOIN Projects p ON e.Department = p.Department;

πŸ“š Module Summary

  • SELECT β€” choose columns
  • WHERE β€” filter rows
  • ORDER BY β€” sort
  • JOIN β€” combine tables

πŸ€” Interview Q&A

Tap the questions to reveal answers.

DISTINCT removes duplicate rows. GROUP BY is used when computing aggregates per group.

Matches any value containing 'abc' anywhere in the string.

ASC (ascending) is default.

INNER returns rows present in both tables; LEFT returns all left rows plus matches (NULLs where no match).

πŸ€–
DSPython AI Assistant βœ–
πŸ‘‹ Hi! I’m your AI assistant. Paste your code here, I will find bugs for you.