1

我正在使用以下查询从两个表中获取数据,它工作正常,但我还想从另外两个平均 4 个表中获取数据

$query = mysql_query("SELECT ml.UserID,ml.ContentAddedDateTime,cat.ContentType,cat.ContentTitle,cat.ContentSource,cat.ContentDescription
  FROM LibraryMaster as ml
  LEFT JOIN CatalogMaster cat ON cat.CatalogID=ml.CatalogID");

我想从 CategoryLookUp 中获取类别,从 SubCategoryLook 中获取 subCategoryTitle

这是 CatalogMaster 表

    CatalogID   int(11)         No      auto_increment                          
CategoryID  int(11)         No                                  
SubCategoryID   int(11)         No                                  
ContentType varchar(10) utf8_general_ci     No                                  
ContentTitle    varchar(25) utf8_general_ci     No                                  
AddedByUserID   int(11)         No                                  
ContentDescription  varchar(250)    utf8_general_ci     Yes NULL                                
ContentSource   varchar(250)    utf8_general_ci     No                                  
ContentAddedDateTime

这是分类查找

    CategoryID  int(11)         No      auto_increment                          
CategoryTitle   varchar(100)    utf8_general_ci     No                                  
CategoryDescription varchar(250)    utf8_general_ci     Yes NULL                                
CategoryAddedByUserID   int(11)         No                                  
CategoryAddedDateTime   

这是 SubCatLookUp

    SubCategoryID   int(11)         No      auto_increment                          
LinkedCategoryID    int(11)         No                                  
SubCategoryTitle    varchar(100)    utf8_general_ci     No                                  
SubCategoryAddedDateTime    timestamp       ON UPDATE CURRENT_TIMESTAMP No  CURRENT_TIMESTAMP                               
SubCategoryAddedByUserID
4

1 回答 1

0
$query = mysql_query("
            SELECT ml.UserID, ml.ContentAddedDateTime, cat.ContentType, cat.ContentTitle, cat.ContentSource, cat.ContentDescription, clu.CategoryTitle, sclu.SubCategoryTitle
               FROM LibraryMaster as ml
                    LEFT JOIN CatalogMaster cat ON cat.CatalogID=ml.CatalogID
                    LEFT JOIN CategoryLookUp clu ON cat.CategoryID = clu.CategoryID
                    LEFT JOIN SubCatLookUp sclu ON cat.SubCategoryID = sclu.SubCategoryID
");

使用上面的查询,

于 2013-06-18T07:15:39.433 回答