CROSS JOIN का उपयोग
CROSS JOIN एक table की हर row को दूसरी table की हर row के साथ pair करता है।
In this page:
Syntax
SELECT columns
FROM table1
CROSS JOIN table2;
CROSS JOIN
Result में rows(A) times rows(B) rows होती हैं और कोई ON condition नहीं। यह sizes by colours जैसे combinations generate करने के लिए useful है। एक missing join condition से accidental cartesian products एक common performance bug हैं।
Note:
Row count दोनों tables का product है, इसलिए inputs छोटी रखें।
उदाहरण: CROSS JOIN
CREATE TABLE sizes (size TEXT);
CREATE TABLE colors (color TEXT);
INSERT INTO sizes VALUES ('S'), ('M'), ('L');
INSERT INTO colors VALUES ('red'), ('blue');
SELECT size, color FROM sizes CROSS JOIN colors ORDER BY size, color;
SELECT COUNT(*) AS combinations FROM sizes CROSS JOIN colors;
-- Output:
-- size | color
-- L | blue
-- L | red
-- M | blue
-- M | red
-- S | blue
-- S | red
-- combinations
-- 6
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 भूल जाना और accidentally एक cross join बनाना
- बड़ी tables पर इसे इस्तेमाल करना
- matches की उम्मीद करना
चैप्टर सारांश
- CROSS JOIN सारी rows pair करता है
- Result size product है
- कोई ON condition नहीं
- Combinations के लिए great
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: