locked
sql compact: Group By RRS feed

  • Question

  • User1519602350 posted

    Hi,

    Below my sql query.

    SELECT a.SubMenuId,  b.Title FROM DropDown a Inner Join Pages b on a.PageId=b.PageId GROUP BY b.Title, a.SubMenuId
    

    I have tried remove GROUP BY b.Title . But it leads to an error.

    SELECT a.SubMenuId,  b.Title FROM DropDown a Inner Join Pages b on a.PageId=b.PageId GROUP BY b.Title, a.SubMenuId
    

    In aggregate and grouping expressions, the SELECT clause can contain only aggregates and grouping expressions. [ Select clause = b,Title ]

    Kindly help me with this.

    Thursday, May 8, 2014 3:32 AM

Answers

  • User1713851783 posted

    I don't understand what is your goal, because generally you use a GROUP BY clause with an aggregate functions like SUM, COUNT, MAX, etc.

    If you want to select only an occurence of the SubMenuId / Title pair, you should use the DISTINCT clause

    SELECT DISTINCT a.SubMenuId,  b.Title FROM DropDown a Inner Join Pages b on a.PageId=b.PageId 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 8, 2014 4:18 AM