⏱ तेज़ Insights
सही index और optimized GROUP BY/WHERE से बड़े queries भी seconds में result दे सकते हैं।
Table of Contents
ToggleSELECT, JOIN, GROUP BY, WINDOW Functions और अन्य SQL कमांड्स का आसान हिंदी विवरण। हर कमांड के साथ Syntax और Practical Example भी दिया गया है ताकि सीखना आसान हो।
👇 नीचे दिए कार्ड्स पर क्लिक करके आप सीधे SQL कमांड के Example तक पहुंच सकते हैं।
SELECT customer_id, SUM(amount) AS total
FROM sales
WHERE sale_date >= '2024-01-01'
GROUP BY customer_id;
SQL (Structured Query Language) बड़े डेटा सेट से तेज़ी से जानकारी निकालने, साफ़ करने और सारांश (aggregate) बनाने के लिए industry-standard टूल है। यह reproducible, readable और production-ready analyses के लिए बुनियादी है।
सही index और optimized GROUP BY/WHERE से बड़े queries भी seconds में result दे सकते हैं।
Queries को version-control में रखें (git) — analysis बनाने और review करने में team को मदद मिलती है।
हर कमांड के साथ real-world use-case और output sample दिखाया गया है।
यह पोस्ट SQL Commands को सरल हिंदी में समझाने के लिए तैयार किया गया है — प्रत्येक कमांड के साथ Syntax, Example और Practical Use-case दिया गया है। नीचे के छोटे, interactive कार्ड्स आपको तेज़ी से पढ़ने, समझने और प्रयोग करने में मदद करेंगे।
Beginners जो SQL fundamentals सीखना चाहते हैं, students और Data Analysts जिन्हें quick reference चाहिए, तथा Developers/Engineers जो production-ready queries बनाना चाहते हैं।
H2/H3 में primary keyword रखें, examples को structured data (JSON-LD) में दें और code blocks को text में रखें (image न करें)।
हर command के पास a) short summary, b) syntax block, c) runnable example — और anchor-links दें ताकि readers jump कर सकें।
नीचे दिए कार्ड्स पर क्लिक करें और सीधे detail sections पर जाएँ। हर कार्ड में command का syntax, छोटा example और practical उपयोग समझाया गया है।
किसी भी table से specific columns और rows fetch करने का तरीका।
SELECT id, name FROM users WHERE active=1;
दो या अधिक tables को जोड़कर relational data analyze करना।
SELECT o.id, c.name
FROM orders o
JOIN customers c ON o.customer_id = c.id;
Aggregations जैसे SUM, COUNT, AVG करके सारांश reports बनाना।
SELECT product_id, SUM(quantity) total_sold
FROM sales
GROUP BY product_id;
Running totals, ranking और time-series analytics के लिए powerful functions।
SELECT id, amount,
SUM(amount) OVER(PARTITION BY customer_id ORDER BY date) running_total
FROM sales;
SELECT किसी table से columns/rows निकालने के लिए मूलभूत SQL कमांड है। यह filter, sort, और आगे की aggregation के लिए input देता है। नीचे छोटा syntax, तुरंत चलाने योग्य example और practical tips दिए गए हैं — copy-paste के लिए optimized।
Use-case
Data preview, simple reports, debug queries
Difficulty
Beginner → Intermediate
SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1 DESC
LIMIT 100;
-- कुल बिक्री प्रति ग्राहक (2025)
SELECT customer_id,
SUM(amount) AS total_spent,
COUNT(*) AS orders_count
FROM sales
WHERE sale_date BETWEEN '2025-01-01' AND '2025-09-30'
GROUP BY customer_id
HAVING SUM(amount) > 1000
ORDER BY total_spent DESC
LIMIT 50;
Pro-tip: pages के अंदर anchor लिंक बनाएं — उदाहरण: #cmd-select
ताकि readers सीधे इस section पर jump कर सकें।
Accessibility: code blocks में keyboard-focus की सुविधा रखें और semantic headings उपयोग करें — screen reader friendly रखने से SEO में भी मदद मिलती है।
JOIN SQL की सबसे power-packed command है, जो दो या अधिक tables को common key (जैसे customer_id) के आधार पर जोड़ती है। Data Analytics में यह relationships निकालने और combined reports बनाने के लिए सबसे ज़्यादा उपयोगी है।
SELECT a.customer_id, a.order_id, b.payment_date
FROM orders a
INNER JOIN payments b
ON a.order_id = b.order_id;
SELECT c.customer_name, o.order_date, o.total_amount
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.order_date >= '2025-01-01'
ORDER BY o.total_amount DESC;
SQL डेटा एनालिटिक्स की backbone है। यह आपको बड़े डेटा से insights निकालने, business problems solve करने और performance optimize करने में मदद करता है।
SELECT और WHERE commands आपको बड़े datasets से relevant डेटा निकालने में मदद करते हैं।
JOIN commands आपको multiple tables connect करके meaningful insights निकालने की सुविधा देते हैं।
GROUP BY और Aggregate functions से summaries और reports generate करना आसान हो जाता है।
नीचे हर कमांड के लिए anchor कार्ड हैं — क्लिक करके सीधे detailed example पर जाएँ। हर कार्ड में छोटा syntax snippet भी दिया गया है।
किसी तालिका से columns चुनने के लिए। analytics में यह सबसे बेसिक और सबसे ज़रूरी।
SELECT name, amount FROM sales;
Rows को condition के आधार पर फ़िल्टर करें — जरूरी जब large datasets में targeted analysis करना हो।
SELECT * FROM sales WHERE sale_date >= '2024-01-01';
Different tables से related data combine करने के लिए — INNER, LEFT, RIGHT, FULL इत्यादि।
SELECT c.name, s.amount FROM customers c JOIN sales s ON c.id = s.customer_id;
Data summarization — totals, averages और अन्य aggregate metrics निकालने के लिए।
SELECT product_id, SUM(amount) total FROM sales GROUP BY product_id;
GROUP BY के बाद समूहों पर filter लगाना — helpful for top-n groups, thresholds आदि।
SELECT product_id, SUM(amount) total FROM sales GROUP BY product_id HAVING SUM(amount) > 10000;
Reports में sorted lists चाहिए हों तो ORDER BY का उपयोग करें — ASC/DESC के साथ।
SELECT name, amount FROM sales ORDER BY amount DESC;
Resultset को small sample में लाने के लिए — debugging और dashboards में उपयोगी।
SELECT * FROM sales ORDER BY amount DESC LIMIT 10;
Running totals, row_number, moving averages — analytics में powerful trends निकालते हैं।
SELECT customer_id, amount,
SUM(amount) OVER (PARTITION BY customer_id ORDER BY sale_date) cumulative
FROM sales;
Complex queries को छोटे logical parts में विभक्त करें — readability और reuse के लिए बेहतरीन।
WITH monthly AS (
SELECT DATE_TRUNC('month', sale_date) m, SUM(amount) total
FROM sales GROUP BY 1
)
SELECT * FROM monthly;
Large queries को optimize करने के लिए EXPLAIN और proper indexes जरूरी होते हैं।
-- Create index CREATE INDEX idx_sales_date ON sales(sale_date); -- Check plan EXPLAIN ANALYZE SELECT * FROM sales WHERE sale_date >= '2024-01-01';
इन cards को detail sections से link करें (उदाहरण: #cmd-select) — users सीधे example पर jump कर सकें।
WHERE clause rows को condition के आधार पर filter करता है — large tables में सही filters लगाना performance और accuracy दोनों के लिए ज़रूरी है।
#cmd-where
जब आप केवल उन rows पर काम करना चाहते हैं जो किसी शर्त को पूरा करती हों — उदाहरण: date range, status, region, या numeric thresholds।
SELECT column1, column2 FROM table_name WHERE condition;
SELECT order_id, sale_date, amount FROM sales WHERE sale_date BETWEEN '2025-01-01' AND '2025-06-30';
Quarterly reports या seasonal analysis के लिए यह pattern बहुत common है।
SELECT customer_id, amount, region FROM sales WHERE region = 'North' AND amount > 1000;
Multiple filters combine करके targeted cohort निकालें।
SELECT email FROM users WHERE email LIKE '%@gmail.com';
Contacts cleanup या domain-specific analysis के लिए उपयोगी।
DATE(col)) index को bypass कर सकते हैं — सावधानी से use करें।LIKE '%term%') expensive होते हैं।WHERE col IS NOT NULL।Tip: preview on mobile and desktop — font-size ~15–16px for body keeps readability high.
JOIN SQL की backbone है — यह multiple tables से related data combine करने देता है। Data Analytics में joins का सही उपयोग करना insights की quality और speed दोनों तय करता है।
#cmd-join
SELECT c.customer_name, s.amount FROM customers c INNER JOIN sales s ON c.id = s.customer_id;
SELECT c.customer_name, s.amount FROM customers c LEFT JOIN sales s ON c.id = s.customer_id;
सभी customers दिखेंगे, भले ही उनकी कोई sales न हो।
SELECT c.region, SUM(s.amount) total_sales FROM customers c JOIN sales s ON c.id = s.customer_id GROUP BY c.region;
Region-wise total sales निकालने का efficient तरीका।
Tip: JOINs में हमेशा EXPLAIN plan देखें — performance surprises से बचने के लिए।
GROUP BY से आप बड़े dataset को meaningful groups में बदलकर totals, averages, और अन्य metrics निकाल सकते हैं — reporting और KPI निर्माण के लिए अनिवार्य tool।
#cmd-groupby
-- Sales को product के हिसाब से summarize करना
SELECT product_id,
COUNT(*) AS orders_count,
SUM(amount) AS total_sales,
AVG(amount) AS avg_order
FROM sales
WHERE sale_date >= '2024-01-01'
GROUP BY product_id
ORDER BY total_sales DESC;
SELECT region, product_id, SUM(amount) total FROM sales GROUP BY ROLLUP(region, product_id);
Region के total और overall total दोनों एक query में मिलता है।
SELECT region, product_id, SUM(amount) total FROM sales GROUP BY GROUPING SETS ((region, product_id),(region),(product_id));
एक से ज़्यादा aggregation combos efficient तरीके से लें।
Tip: हर aggregation के साथ example output का छोटा snippet दिखाएँ — users और search engines दोनों को पसंद आता है।
HAVING clause का उपयोग GROUP BY के बाद aggregated results पर condition लगाने के लिए किया जाता है। यह आपको summary tables से meaningful subsets निकालने में मदद करता है — जैसे high-value customers या top-performing products।
#cmd-having
SELECT column, SUM(amount) AS total FROM sales GROUP BY column HAVING SUM(amount) > 10000;
यहाँ हम सिर्फ उन्हीं groups को रखते हैं जिनका total 10,000 से अधिक है।
SELECT customer_id, SUM(amount) total_sales FROM sales GROUP BY customer_id HAVING SUM(amount) > 5000 ORDER BY total_sales DESC;
सिर्फ वही customers दिखेंगे जिनकी कुल बिक्री 5000 से अधिक है।
Tip: HAVING examples को अक्सर interview में पूछा जाता है — इस section को bookmark करें।
ORDER BY clause किसी भी query के परिणामों को Ascending (ASC) या Descending (DESC) order में sort करने के लिए उपयोग किया जाता है। Reports, dashboards और ranking-based insights के लिए यह सबसे ज़्यादा इस्तेमाल होता है।
#cmd-orderby
SELECT column1, column2 FROM table ORDER BY column1 ASC, column2 DESC;
आप एक या एक से अधिक columns पर sort कर सकते हैं — ASC (default) या DESC।
SELECT product_id, amount FROM sales ORDER BY amount DESC LIMIT 10;
बिक्री राशि के आधार पर शीर्ष 10 products दिखेंगे।
SELECT customer_name, SUM(amount) total FROM sales GROUP BY customer_name ORDER BY customer_name ASC, total DESC;
पहले नाम alphabetically और फिर total sales descending order में।
Tip: ORDER BY interview में अक्सर पूछा जाता है — especially performance tuning के साथ।
LIMIT या FETCH clause का उपयोग resultset को छोटा करने के लिए किया जाता है — debugging, dashboards, और Top-N रिपोर्ट्स के लिए बेहद उपयोगी। अलग-अलग RDBMS में syntax थोड़ा बदल सकता है (Postgres/MySQL vs SQL Server) — दोनों variants नीचे दिए हैं।
#cmd-limit
SELECT * FROM sales ORDER BY amount DESC LIMIT 10 OFFSET 0;
SELECT * FROM sales ORDER BY amount DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;
ध्यान दें: OFFSET के बिना LIMIT/FETCH का उपयोग अक्सर predictable रहता है — पर pagination में OFFSET ज़रूरी होता है।
SELECT customer_id, SUM(amount) total FROM sales GROUP BY customer_id ORDER BY total DESC LIMIT 5;
-- page_number = 3, page_size = 20 OFFSET 40 LIMIT 20; -- Postgres/MySQL -- or SQL Server: OFFSET 40 ROWS FETCH NEXT 20 ROWS ONLY;
Tip: Live demos के लिए LIMIT रखें ताकि readers तुरंत output देख सकें।
CTE (Common Table Expression) जटिल queries को छोटे logical blocks में बदल देता है — जिससे readability और debugging आसान हो जाती है।
WITH sales_monthly AS (
SELECT DATE_TRUNC('month', sale_date) AS month,
SUM(amount) total
FROM sales
GROUP BY 1
)
SELECT * FROM sales_monthly;
ORDER BY का उपयोग query results को ascending (ASC) या descending (DESC) order में लाने के लिए किया जाता है। Reporting और dashboards में यह सबसे ज़्यादा helpful होता है।
SELECT customer_id, amount
FROM sales
ORDER BY amount DESC;
यह query सभी customers को उनके sales amount के हिसाब से descending order में दिखाएगी।
नीचे दिए गए आसान SQL Queries को खुद ट्राई करें।
Example datasets: Employees, Orders, Products
SELECT * FROM Employees;
SELECT EmployeeID, FirstName, LastName, Department
FROM Employees;
SELECT FirstName, LastName, Department, Salary
FROM Employees
WHERE Department = 'Analytics';
SELECT p.ProductName, SUM(o.SalesAmount) AS TotalSales
FROM Products p
JOIN Orders o ON p.ProductID = o.ProductID
GROUP BY p.ProductName;
SELECT p.ProductName, SUM(o.SalesAmount) AS TotalSales
FROM Products p
JOIN Orders o ON p.ProductID = o.ProductID
GROUP BY p.ProductName
HAVING SUM(o.SalesAmount) > 1000;
👉 Pro Tip: इन Queries को चलाने के लिए पहले Employees, Orders, Products tables बनाइए।
(चाहें तो मैं आपके लिए INSERT sample data भी बना दूँ)
अब जब आपने SQL Commands सीख लिए हैं, तो इन्हें Real-World Data Analytics Projects में आज़माइए। Vista Academy में हम आपको SQL, Excel, Python और Power BI से Job-Ready Data Analyst बनने में मदद करते हैं।
🎯 Join Our Data Analytics Course