SQL SELECT 多表查询
商品表(product):
如图:
在线咨询表(consultation):
如图:
商品图片表(productphotos):
如图:
问题是如何查询出这样的结果集?
比如:
[解决办法]
select top(1) b.id,b.title,b.content,b.productId,a.producttitle,a.promotionPrice,c.ProductPhotofrom product a ,consultation b ,productphotos cwhere a.productId = b.productId and a.productId = c.productIdgroup by b.id,b.title,b.content,b.productId,a.producttitle,a.promotionPriceorder by c.ReleaseTime desc
[解决办法]
try
SELECT commt.Id,commt.Title,commt.Content,commt.ProductID,prod.ProductTitle,prod.PromotionPrice,prodimg.ProductPhoto FROM commentary AS commt INNER JOIN product AS prod on(commt.ProductID=prod.Id)INNER JOIN productphotos AS prodimg ON(prod.Id=prodimg.ProductID)WHERE prodimg.releasetime=(select top 1 releasetime from productphotos where ProductID=commt.ProductID and releasetime>=commt.dateandtime order by releasetime)