CROSS JOIN in MySQL : Cross Join « Join « SQL / MySQL

SQL / MySQL
1. Backup Load
2. Command MySQL
3. Cursor
4. Data Type
5. Database
6. Date Time
7. Flow Control
8. Function
9. Insert Delete Update
10. Join
11. Key
12. Math
13. Procedure Function
14. Select Clause
15. String
16. Table Index
17. Transaction
18. Trigger
19. User Permission
20. View
21. Where Clause
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL / MySQL » Join » Cross Join 
CROSS JOIN in MySQL

/*

mysql> SELECT ArticleTitle, AuthID FROM Articles CROSS JOIN AuthorArticle;
+-------------------+--------+
| ArticleTitle      | AuthID |
+-------------------+--------+
| How write a paper |   1006 |
| Publish a paper   |   1006 |
| Sell a paper      |   1006 |
| Buy a paper       |   1006 |
| Conferences       |   1006 |
| Journal           |   1006 |
| Information       |   1006 |
| AI                |   1006 |
| How write a paper |   1008 |
| Publish a paper   |   1008 |
| Sell a paper      |   1008 |
| Buy a paper       |   1008 |
| Conferences       |   1008 |
| Journal           |   1008 |
| Information       |   1008 |
| AI                |   1008 |
| How write a paper |   1009 |
| Publish a paper   |   1009 |
| Sell a paper      |   1009 |
| Buy a paper       |   1009 |
| Conferences       |   1009 |
| Journal           |   1009 |
| Information       |   1009 |
| AI                |   1009 |
| How write a paper |   1010 |
| Publish a paper   |   1010 |
| Sell a paper      |   1010 |
| Buy a paper       |   1010 |
| Conferences       |   1010 |
| Journal           |   1010 |
| Information       |   1010 |
| AI                |   1010 |
| How write a paper |   1011 |
| Publish a paper   |   1011 |
| Sell a paper      |   1011 |
| Buy a paper       |   1011 |
| Conferences       |   1011 |
| Journal           |   1011 |
| Information       |   1011 |
| AI                |   1011 |
| How write a paper |   1012 |
| Publish a paper   |   1012 |
| Sell a paper      |   1012 |
| Buy a paper       |   1012 |
| Conferences       |   1012 |
| Journal           |   1012 |
| Information       |   1012 |
| AI                |   1012 |
| How write a paper |   1012 |
| Publish a paper   |   1012 |
| Sell a paper      |   1012 |
| Buy a paper       |   1012 |
| Conferences       |   1012 |
| Journal           |   1012 |
| Information       |   1012 |
| AI                |   1012 |
| How write a paper |   1014 |
| Publish a paper   |   1014 |
| Sell a paper      |   1014 |
| Buy a paper       |   1014 |
| Conferences       |   1014 |
| Journal           |   1014 |
| Information       |   1014 |
| AI                |   1014 |
+-------------------+--------+
64 rows in set (0.01 sec)


*/

Drop table Articles;
Drop table Authors;
Drop table AuthorArticle;



CREATE TABLE Articles (
   ArticleID SMALLINT NOT NULL PRIMARY KEY,
   ArticleTitle VARCHAR(60NOT NULL,
   Copyright YEAR NOT NULL
)
ENGINE=INNODB;


INSERT INTO Articles VALUES (12786'How write a paper', 1934),
                            (13331'Publish a paper', 1919),
                            (14356'Sell a paper', 1966),
                            (15729'Buy a paper', 1932),
                            (16284'Conferences', 1996),
                            (17695'Journal', 1980),
                            (19264'Information', 1992),
                            (19354'AI', 1993);


CREATE TABLE Authors (
   AuthID SMALLINT NOT NULL PRIMARY KEY,
   AuthorFirstName VARCHAR(20),
   AuthorMiddleName VARCHAR(20),
   AuthorLastName VARCHAR(20)
)
ENGINE=INNODB;


INSERT INTO Authors VALUES (1006'Henry', 'S.', 'Thompson'),
                           (1007'Jason', 'Carol', 'Oak'),
                           (1008'James', NULL, 'Elk'),
                           (1009'Tom', 'M''Ride'),
                           (1010'Jack', 'K''Ken'),
                           (1011'Mary', 'G.', 'Lee'),
                           (1012'Annie', NULL, 'Peng'),
                           (1013'Alan', NULL, 'Wang'),
                           (1014'Nelson', NULL, 'Yin');


CREATE TABLE AuthorArticle (
   AuthID SMALLINT NOT NULL,
   ArticleID SMALLINT NOT NULL,
   PRIMARY KEY (AuthID, ArticleID),
   FOREIGN KEY (AuthIDREFERENCES Authors (AuthID),
   FOREIGN KEY (ArticleIDREFERENCES Articles (ArticleID)
)
ENGINE=INNODB;


INSERT INTO AuthorArticle VALUES (100614356)
                              (100815729)
                              (100912786)
                              (101017695),
                              (101115729)
                              (101219264)
                              (101219354)
                              (101416284);
  
SELECT ArticleTitle, AuthID FROM Articles CROSS JOIN AuthorArticle;


           
       
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.