如何从四个表中获取数据?
我有四张桌子:
ArticleName, ArticleNumber
)IndexSubMasterId, ArticleNumber
)IndexSubMasterId, IndexMasterId
)IndexMasterId, Keyword
)我需要最终输出:
ArticleName from Article table.
我将为您提供Keyword
作为输入参数。
我需要的过程是:
IndexMasterId From IndexMaster_Table where Keyword = 'bl'
IndexSubMasterId From IndexSubMaster_Table
Where IndexSubMaster_Table.IndexMasterId = IndexMaster_Table.IndexMasterId
ArticleNumber From IndexDetails_Table
Where IndexDetails_Table.IndexSubMasterId = IndexSubMaster_Table.IndexSubMasterId
ArticleName From Article_Table
Where Article_Table.ArticleNumber = IndexDetails_Table.ArticleNumber
答案 0 :(得分: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