-1

如何从四个表中获取数据?

我有四张桌子:

  • Article_Table ( ArticleName, ArticleNumber)
  • IndexDetails_Table ( IndexSubMasterId, ArticleNumber)
  • IndexSubMaster_Table ( IndexSubMasterId, IndexMasterId)
  • IndexMaster_Table ( IndexMasterId, 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

4

1 回答 1

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
于 2012-08-08T12:52:04.943 回答