← Back to PostgreSQL Course | Chapter 6: Joins | Lesson 5 of 7

CROSS JOIN का उपयोग

CROSS JOIN एक table की हर row को दूसरी table की हर row के साथ pair करता है।

In this page:

  1. CROSS JOIN
Syntax
sql
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

sql
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
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. #}
आम गलतियां
  1. ON condition भूल जाना और accidentally एक cross join बनाना
  2. बड़ी tables पर इसे इस्तेमाल करना
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.