combine three tables

Reply

Join Date: Nov 2007
Posts: 183
Reputation: lydia21 is an unknown quantity at this point 
Solved Threads: 5
lydia21 lydia21 is offline Offline
Junior Poster

combine three tables

 
0
  #1
Aug 7th, 2008
hi
how to combine three tables in a single query.please send a sample code
thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,191
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: combine three tables

 
-1
  #2
Aug 7th, 2008
Check out the Referring to Two Tables example
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: combine three tables

 
0
  #3
Aug 8th, 2008
this is one example:
this is based on joins...
  1. CREATE TABLE Articles (
  2. ArticleID SMALLINT NOT NULL PRIMARY KEY,
  3. ArticleTitle VARCHAR(60) NOT NULL,
  4. Copyright YEAR NOT NULL
  5. )
  6. ENGINE=INNODB;
  7.  
  8.  
  9. INSERT INTO Articles VALUES (12786, 'How write a paper', 1934),
  10. (13331, 'Publish a paper', 1919),
  11. (14356, 'Sell a paper', 1966),
  12. (15729, 'Buy a paper', 1932),
  13. (16284, 'Conferences', 1996),
  14. (17695, 'Journal', 1980),
  15. (19264, 'Information', 1992),
  16. (19354, 'AI', 1993);
  17.  
  18.  
  19. CREATE TABLE Authors (
  20. AuthID SMALLINT NOT NULL PRIMARY KEY,
  21. AuthorFirstName VARCHAR(20),
  22. AuthorMiddleName VARCHAR(20),
  23. AuthorLastName VARCHAR(20)
  24. )
  25. ENGINE=INNODB;
  26.  
  27.  
  28. INSERT INTO Authors VALUES (1006, 'Henry', 'S.', 'Thompson'),
  29. (1007, 'Jason', 'Carol', 'Oak'),
  30. (1008, 'James', NULL, 'Elk'),
  31. (1009, 'Tom', 'M', 'Ride'),
  32. (1010, 'Jack', 'K', 'Ken'),
  33. (1011, 'Mary', 'G.', 'Lee'),
  34. (1012, 'Annie', NULL, 'Peng'),
  35. (1013, 'Alan', NULL, 'Wang'),
  36. (1014, 'Nelson', NULL, 'Yin');
  37.  
  38.  
  39. CREATE TABLE AuthorArticle (
  40. AuthID SMALLINT NOT NULL,
  41. ArticleID SMALLINT NOT NULL,
  42. PRIMARY KEY (AuthID, ArticleID),
  43. FOREIGN KEY (AuthID) REFERENCES Authors (AuthID),
  44. FOREIGN KEY (ArticleID) REFERENCES Articles (ArticleID)
  45. )
  46. ENGINE=INNODB;
  47.  
  48.  
  49. INSERT INTO AuthorArticle VALUES (1006, 14356),
  50. (1008, 15729),
  51. (1009, 12786),
  52. (1010, 17695),
  53. (1011, 15729),
  54. (1012, 19264),
  55. (1012, 19354),
  56. (1014, 16284);
  57.  
  58. SELECT STRAIGHT_JOIN ArticleTitle, Copyright,
  59. CONCAT_WS(' ', AuthorFirstName, AuthorMiddleName, AuthorLastName) AS Author
  60. FROM Articles AS b, AuthorArticle AS ab, Authors AS a
  61. WHERE b.ArticleID=ab.ArticleID AND ab.AuthID=a.AuthID AND Copyright<1980
  62. ORDER BY ArticleTitle;
see this for reference:
http://www.tizag.com/mysqlTutorial/mysqljoins.php
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC