2012-08-08 61 views
-1

如何從四個表中提取數據?從四個表中提取數據

我有四個表:

  • Article_TableArticleName, ArticleNumber
  • IndexDetails_TableIndexSubMasterId, ArticleNumber
  • IndexSubMaster_TableIndexSubMasterId, IndexMasterId
  • IndexMaster_TableIndexMasterId, Keyword

我需要最終輸出:

ArticleName from Article table. 

我將爲您提供一個Keyword作爲輸入參數。

,我需要將過程:

  1. IndexMasterId From IndexMaster_Table where Keyword = 'bl'

  2. IndexSubMasterId From IndexSubMaster_Table
    Where IndexSubMaster_Table.IndexMasterId = IndexMaster_Table.IndexMasterId

  3. ArticleNumber From IndexDetails_Table Where IndexDetails_Table.IndexSubMasterId = IndexSubMaster_Table.IndexSubMasterId

  4. ArticleName From Article_Table
    Where Article_Table.ArticleNumber = IndexDetails_Table.ArticleNumber

+0

這是關係到iPhone?我不這麼認爲 – TheTiger 2012-08-08 12:05:26

+0

這與iPhone無關。抱歉!!!! – 2012-08-08 12:08:21

+0

感謝marc_s進行編輯。 – 2012-08-08 12:30:19

回答

0

試試這個我肯定有更有效的方法,但這裏是東西給你

Declare @keyword varchar(20) 
Set @keyword = 'bl' 

Select article.ArticleName FROM IndexMaster_Table masterTable 
JOIN IndexSubMaster_Table subMaster 
on masterTable.IndexMasterId = subMaster.IndexMasterId 
JOIN IndexDetails_Table details 
on details.IndexSubMasterId = subMaster.IndexSubMasterId 
JOIN Article_Table article 
on article.ArticleNumber = details.ArticleNumber 
Where masterTable.keyword = @keyword 
+0

謝謝Jamie.This方法完美工作,花費更少的時間來執行。 – 2012-08-08 19:51:29

+0

沒問題,很高興幫助 – 2012-08-09 03:33:16