与在sql中连接三个表有关 [英] Related to joining three tables in sql

查看:76
本文介绍了与在sql中连接三个表有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

i有加入三张桌子的问题,

i有三张桌子-----

1. sublevelcatalogue其中我有列''productTypeId'',''CatalogueId'',

2.finallevelcatalogue其中我有列''productTypeId ''''productId'',''productname''



3.imagemaster我有列''imageId'',''imagepath'',''productId''



一个上有多个图像''productId''我希望只选择所有产品的第一张图片...我正在使用SQL数据库

如何加入这些表,,,,给出建议... .thnx提前

hello all,
i have a problem related to joining three tables,
i have three tables -----
1. " sublevelcatalogue" in which i have column ''productTypeId'',''CatalogueId'',
2. "finallevelcatalogue" in which i have column ''productTypeId'' , ''productId'' , ''productname''

3. "imagemaster" in which i have column ''imageId'',''imagepath'',''productId''

there are multiple image on one ''productId'' and i want to select only first image for all product... I AM USING SQL DATABASE
how to join these tables,,,,give suggetions....thnx in advance

推荐答案

你好





你想要的结果喜欢那样: -

productId,productTypeId,CatalogueId,imageId,imagepath所以你可以使用



Hello


You Want to Result Like That:-
productId,productTypeId,CatalogueId,imageId,imagepath So Simply You Can Use

SELECT f.productId,f.productTypeId,CatalogueId,imageId,imagepath 
 FROM finallevelcatalogue f
INNER JOIN imagemaster ON f.productId = imagemaster.productId
INNER JOIN
(
   SELECT Top 1 ImageID, imagepath ,productId FROM imagemaster where productId=f.productId 
  
) tab ON f.productId= tab.productId





它会给你带来Recore Associated如果产品ID我希望您的问题解决如果不给我您的评论



It Will Give You ONe Recore Associated To PRoduct Id I Hope Your Problem Will Solve IF not Give me Your Review


尝试以下查询获取每个的第一个图像ProductID
Try the below query to get the first image for each ProductID
SELECT * FROM finallevelcatalogue FLC
INNER JOIN imagemaster IM ON FLC.productId = IM.productId
INNER JOIN
(
   SELECT MIN(ImageID) AS ImageID, productId FROM imagemaster
   GROUP BY productId  
) T ON IM.ImageID = T.ImageID


这篇关于与在sql中连接三个表有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆