I have This type of query when I execute it it return duplicate row in table,,
what’s the problem with this ?????
Declare @Keyword AS NVARCHAR(MAX)
Set @Keyword = 'scale'
select DISTINCT * from (
SELECT DISTINCT dbo.Product_Search.Product_Name, dbo.Product_Search.Product_Code,
dbo.Product_Search.Product_ModelNo, dbo.Brand_Master.Brand_Name,
dbo.Product_Search.Product_Kid, dbo.Product_Search.Product_Image,
dbo.Unit_Master.Unit_Name, dbo.product_Search.CatName,
dbo.product_Search.ProdName, dbo.product_Search.ProductDescription, ROW_NUMBER() over(order by Product_Kid) as ROW
FROM dbo.Product_Search INNER JOIN
dbo.Brand_Master ON dbo.Product_Search.Product_BrandId = dbo.Brand_Master.Brand_Kid LEFT OUTER JOIN
dbo.Category_Index_Master ON dbo.Product_Search.Product_CategoryId = dbo.Category_Index_Master.Category_Kid LEFT OUTER JOIN
dbo.Unit_Master ON dbo.Product_Search.Product_MarketPriceType = dbo.Unit_Master.Unit_Kid
WHERE (dbo.Product_Search.Product_Name LIKE '%' + @Keyword + '%')
OR CategoryIndex_Name LIKE '%' + @Keyword + '%'
OR Brand_Name LIKE '%' + @Keyword + '%'
OR Product_ModelNo LIKE '%' + @Keyword + '%'
OR Product_Code LIKE '%' + @Keyword + '%'
)h
Row_Number:
http://msdn.microsoft.com/en-us/library/ms186734.aspx
So you will have non-unique values always here. Let you try to move ROW to upward: