Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried multiple time but result show multi value in out put . I have three table one for productimage(Imageid,Pid,ImageName,Imageextention) second for brands(Brandid,Name) and third one is products(PID,PBrandid,PImageid etc) output show multiple brandname but i want brandname not repeat

What I have tried:

select distinct b.Name,A.*,C.* from tblProduct A inner join tblBrands B  on A.PBrandID = B.BrandId
cross apply(
select top 1 * from tblProductImages C where A.PId= c.PID  order by b.Name desc
)C
order by b.Name desc
Posted
Updated 18-Mar-21 4:22am

1 solution

DISTINCT returns rows that are entirely different, not rows that contain a single different column (unless you only return a single column).

So if there are 3 rows with identical Brands but different Names and you return both columns with DISTINCT you will get three rows. If you omit the Name column, you will get a single row.

The problem is that you don't describe a criteria by which SQL could decide which row of the three to return: you need to work out which of your images should be used for the Brand and then work out how to indicate that in SQL before you start coding a query!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900