INNER JOIN का उपयोग
INNER JOIN सिर्फ वे rows return करता है जिनका दोनों tables में एक match है।
In this page:
Syntax
SELECT columns
FROM table1
INNER JOIN table2 ON table1.key = table2.key;
INNER JOIN
JOIN ... ON एक condition इस्तेमाल करके rows pair करता है, usually एक foreign key एक primary key के बराबर। दूसरी table में partner न रखने वाली rows drop हो जाती हैं।
Table aliases queries को short रखते हैं, और alias से columns qualify करना ambiguity हटाता है।
अकेला JOIN मतलब INNER JOIN।
Note:
joins में हमेशा column names table aliases से qualify करें।
उदाहरण: INNER JOIN
CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER, total INTEGER);
INSERT INTO customers VALUES (1, 'Ada'), (2, 'Bob'), (3, 'Cy');
INSERT INTO orders VALUES (10, 1, 50), (11, 1, 20), (12, 2, 75);
SELECT c.name, o.id AS order_id, o.total FROM customers c INNER JOIN orders o ON o.customer_id = c.id ORDER BY o.id;
-- Output:
-- name | order_id | total
-- Ada | 10 | 50
-- Ada | 11 | 20
-- Bob | 12 | 75
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- ON condition भूल जाना और एक cartesian product पाना
- Column names को ambiguous छोड़ना
- यह उम्मीद करना कि unmatched rows appear होंगी
चैप्टर सारांश
- INNER JOIN सिर्फ matching rows रखता है
- ON match define करता है
- Aliases queries छोटी करते हैं
- JOIN मतलब INNER JOIN है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: