Exam में 80%+ score करें और जीतें Certificate + Gifts!
- ✅ पूरा course free
- 🎓 Final Exam में 80%+ = Certificate
- 📝 50 Questions
- 🎁 Cheat Sheet + Gifts + बहुत कुछ
🧭 Never seen SQL before? Just understand these 4 things!
SQL कोई कठिन programming नहीं है। सोचिए आपके पास एक Excel Sheet खुली है और आप उसे type करके बोल रहे हैं कि क्या करना है:
SELECT (what to see) + FROM (from which sheet) + WHERE (what the filter is).
⚡ Live Interactive SQL Sandbox (Browser Engine)
AlaSQL Engine Activeयहाँ आप live SQL queries चलाकर देख सकते हैं! नीचे दिए गए quick buttons पर click करें या अपना SQL code लिखकर Run Query (Ctrl + Enter) दबाएँ:
🗄️ Active Sandbox Data Tables (Our Sample Data)
Sheet 1: Customers 4 Rows
| CustomerID | CustomerName | City | Country |
|---|---|---|---|
| 1 | Amit Sharma | Delhi | India |
| 2 | Pooja Verma | Mumbai | India |
| 3 | John Miller | Berlin | Germany |
| 4 | Sara Smith | London | UK |
Sheet 2: Employees 4 Rows
| EmpID | Name | dept_id | Salary |
|---|---|---|---|
| 101 | Rahul Roy | 10 | 65000 |
| 102 | Sneha Rao | 20 | 48000 |
| 103 | Vikas Jain | 10 | 72000 |
| 104 | Karan Mehta | NULL | 42000 |
Sheet 3: Products 4 Rows
| ProductID | ProductName | Price | SupplierID |
|---|---|---|---|
| 1 | Mechanical Keyboard | 45 | 1 |
| 2 | Gaming Mouse | 25 | 1 |
| 3 | HD Monitor | 180 | 2 |
| 4 | USB Hub | 15 | 3 |
1. SQL Basics & Queries (Everyday Basic Commands)
SQL SELECT & FROM
Pull out just the columns you want from the sheet.
* (star). Very simple.
SQL SELECT DISTINCT
Remove repeated values and see only the unique ones.
SQL WHERE
Add a condition and get only the rows that match it.
SQL AND, OR, NOT
Combine more than one condition together.
SQL ORDER BY
Arrange data from smallest to largest or the other way round.
SQL INSERT INTO
Add a brand new row to the table.
SQL UPDATE
Fix data that is wrong without touching the rest of the table.
SQL DELETE
Remove a row from the table for good.
SQL LIMIT / TOP
See only the first few records. (LIMIT in MySQL / PostgreSQL / SQLite, TOP in SQL Server / MS Access)
SQL NULL Values
Check whether a box is empty or not.
IS NULL, not = NULL.
2. SQL Aggregate Functions (Automatic Maths and Totals)
SQL MIN() & MAX()
Find the smallest and the largest number.
SQL COUNT(), SUM(), AVG()
Find how many there are, the total, and the average.
3. Advanced Querying & Joins (Smart Search and Joining Two Sheets)
SQL LIKE & Wildcards (%)
Search by the first or last letters of a name.
SQL BETWEEN & IN
Search within a range, or among a few chosen options.
SQL Aliases (AS)
Give a column a new, nicer name, that's all.
cust_first_nm, but on screen you want to show Client_Name. That is what an alias does.
SQL INNER JOIN
Join two separate sheets using a common ID.
dept_id and you get one big table. That is JOIN.
SQL GROUP BY & HAVING
Make groups of rows with the same values and get a summary.
SQL CASE Statement
Make decisions based on a condition, i.e. if-else.
SQL COALESCE / IFNULL
Show a default value in place of an empty (NULL) spot.
SQL UNION
Stack two lists one below the other into one long list.
4. Database & Table Management (नई File और Sheet बनाना)
SQL CREATE TABLE
Create a brand new empty table.
SQL ALTER TABLE
Add a new column to an existing table, or remove one.
SQL Primary Key
An ID number that uniquely identifies each row.
SQL AUTO_INCREMENT / IDENTITY
The ID goes up by itself, 1, 2, 3, with every new entry. (AUTO_INCREMENT in MySQL, IDENTITY in SQL Server)
5. Stored Procedures & Security (Shortcut और सुरक्षा)
SQL Stored Procedure
Save a big query under a name so you don't have to type it again. (CALL in MySQL, EXEC in SQL Server)
DELIMITER इसलिए बदलते हैं ताकि procedure के अंदर का ; पूरी command को बीच में न काट दे। PostgreSQL (11+) में भी CALL चलता है, पर procedure की body लिखने का तरीका अलग है।
SQL Comments (--)
Leave a note for yourself next to the code.
GROUP BY लगाकर HAVING COUNT(*) > 1 check करते हैं, तो सारे duplicate records निकलकर आ जाते हैं:
| Feature | DELETE (DML) | TRUNCATE (DDL) | DROP (DDL) |
|---|---|---|---|
| करता क्या है | Rows को एक-एक करके हटाता है | सारी rows को एक झटके में खाली करता है | Table और उसके structure दोनों को मिटा देता है |
| WHERE Clause | हाँ (Specific rows filter कर सकते हैं) | नहीं (पूरी sheet साफ़ होगी) | नहीं |
| Rollback | हाँ (Transactions के साथ वापस आ सकता है) | नहीं (बहुत मुश्किल / Engine dependent) | नहीं (Permanently delete) |
| Speed | Slow (हर row का log बनता है) | Very Fast (Storage de-allocate करता है) | Fastest |
e और m) देकर आपस में जोड़ने को SELF JOIN कहते हैं:
SUM(), AVG() नहीं चलते।• HAVING:
GROUP BY होने के बाद calculated summary पर filter लगाता है (जैसे HAVING COUNT(*) > 2)।
2. NULL Value: Primary key कभी भी
NULL नहीं हो सकती। लेकिन Unique key में NULL allow होता है।3. उपयोग: Primary Key row की पहचान होती है। Unique key extra unique data के लिए होती है।
- ROW_NUMBER(): हमेशा लगातार अलग number देगा:
1, 2, 3, 4. - RANK(): बराबर आने पर rank repeat करेगा, फिर अगला number skip करेगा:
1, 2, 2, 4. - DENSE_RANK(): बराबर आने पर rank repeat करेगा, और कोई number skip नहीं करेगा:
1, 2, 2, 3.
' OR '1'='1 लिखकर बिना password के data access कर लेता है।बचाव (Defense): हमेशा Parameterized Queries (Prepared Statements) का use करें।
• फ़ायदा (Pros):
SELECT और WHERE search speed 100x fast हो जाती है।• नुकसान (Cons): Write operation (
INSERT/UPDATE) थोड़ा slow हो जाता है और extra storage लगती है।
📁 Database Schema:
1. Users (ग्राहक) 5 Rows
| user_id | name | city |
|---|---|---|
| 1 | Aman Gupta | Delhi |
| 2 | Riya Sen | Mumbai |
| 3 | Kabir Das | Delhi |
| 4 | Neha Sharma | Bangalore |
| 5 | Varun Joshi | Jaipur |
2. Items (सामान) 4 Rows
| item_id | title | price (₹) |
|---|---|---|
| 101 | Wireless Earbuds | 1200 |
| 102 | Fast Charger | 500 |
| 103 | Smart Watch | 2500 |
| 104 | Laptop Stand | 800 |
3. Orders (Sales Record) 5 Rows
| order_id | user_id | item_id | status |
|---|---|---|---|
| 501 | 1 | 101 | Delivered |
| 502 | 2 | 103 | Delivered |
| 503 | 1 | 102 | Delivered |
| 504 | 3 | 103 | Cancelled |
| 505 | 4 | 104 | Delivered |