Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 973363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:16:04+00:00 2026-05-16T03:16:04+00:00

If I place DISTINCT keyword i get an error other wise it is working

  • 0

If I place DISTINCT keyword i get an error other wise it is working fine.

ERROR: Msg 145, Level 15, State 1, Procedure SP_Products_GetList, Line 15
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

ALTER PROCEDURE [dbo].[SP_Products_GetList]    

@CatID int,
@CatName int,
@IsNew bit,
@InActive bit,
@SortBy varchar(50),
@SortType varchar(50)

AS    

SELECT DISTINCT Products.ProductID, ProductName, MAX(Price) Price, PriceID, [Description], Size, IsNew, InActive FROM (SELECT * FROM Products WHERE (@InActive is null or @InActive = InActive  ) AND ( @IsNew is null or @IsNew = IsNew )) Products
    INNER JOIN  ProductCategory
        on Products.ProductID = ProductCategory.ProductID 
    INNER JOIN  (
                    SELECT * FROM Categories 
                        WHERE 
                            ( @CatID is null or @CatID = CatID ) and
                            ( @CatName is null or @CatName = CatName )
                ) Categories 
        on ProductCategory.CatID = Categories.CatID 
    INNER JOIN ( 
                    SELECT Prices.ProductID, Prices.Price, Prices.PriceID, Prices.SizeID  FROM Prices 
                        INNER JOIN (
                            SELECT ProductID, max(Price) Price from Prices WHERE PriceID IN 
                                    ( SELECT MAX(PriceID) FROM Prices 
                                    GROUP BY ProductID , SizeID)
                            GROUP BY ProductID )  Prices_
                        ON Prices.ProductID = Prices_.ProductID AND Prices.Price = Prices_.Price                     
                ) as Prices 
        on Prices.ProductID = Products.ProductID 
        inner join  Sizes 
        on Sizes.SizeID = Prices.SizeID 
GROUP BY ProductName, CatName, Products.ProductID, Price, PriceID, [Description] ,Size, IsNew,InActive 
ORDER BY 
CASE @SortType 
    WHEN 'desc' THEN  
    CASE @SortBy         
        WHEN 'ProductName' THEN ProductName        
        END  
    END 
    DESC, 
CASE @SortType 
    WHEN 'desc' THEN  
    CASE @SortBy         
        WHEN 'ProductID' THEN Products.ProductID
        WHEN 'Price' THEN Price          
        END  
    END 
    DESC,     
CASE @SortType 
    WHEN 'asc' THEN  
    CASE @SortBy         
        WHEN 'ProductName' THEN ProductName        
        END  
    END 
    ASC, 
CASE @SortType 
    WHEN 'asc' THEN  
    CASE @SortBy         
        WHEN 'ProductID' THEN Products.ProductID
        WHEN 'Price' THEN Price          
        END  
    END 
    ASC
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:16:04+00:00Added an answer on May 16, 2026 at 3:16 am

    What happens if you do…

    SELECT ProductID, ProductName...
    FROM (
           SELECT DISTINCT Products.ProductID, ProductName...
    ) AS OrderProduct
    ORDER BY [your order code...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I place many checks of the program state, whose failure would indicate a bug
I want to get the distinct values in a list, but not by the
I have a model class Place, which has a field for state, and I
Working with class/id selectors in CSS and in jQuery, I often see two distinct
My place of work currently uses CVS. A git migration is planned but it
Every place I've worked in the past 15 years has had, on almost every
I place the .html (which consist of the .js web link) file in the
Every place I have looked all I can find is how to read a
I want to place a login inline-form in a twitter navbar. I have done
I want to place panels horizontally, but when I drag panels they are going

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.