locked
SQL compact query RRS feed

  • Question

  • User1519602350 posted

    Sql Query:

    SELECT a.SubMenuId, a.PageId, b.SubMenuName FROM DropDown a Inner Join SubMenu b on a.SubMenuID=b.Id GROUP BY b.SubMenuName, a.submenuid,a.PageId
    

    Result:

    submenuid       Pagetitle               title

    168               150 Corporate News
    168               162 Corporate News
    163               120 Corporate Overview
    163               121 Corporate Overview
    163               124 Corporate Overview
    163               125 Corporate Overview
    163               168 Corporate Overview
    163               175 Corporate Overview

    Expecting result:

    submenuid       pageid        title

    168                175          Corporate News
    163                168     Corporate Overview

    Thanks

    Thursday, May 8, 2014 6:53 AM

Answers

  • User1713851783 posted

    Supposing that the last record in your result is "168 175 Corporate News" and not "163 175 Corporate Overview" as you report, you should try something like

    SELECT a.SubMenuId, a.Page, b.SubMenuName FROM SubMenu b INNER JOIN (
       SELECT SubMenuId, MAX(PageId) AS Page FROM DropDown GROUP BY SubMenuId
    ) a ON a.SubMenuID = b.Id

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

All replies

  • User-1353043493 posted

    There is no any recored like

    submenuid       pageid        title

    168                175          Corporate News

    Please check and update your requirment. so i will help you

    provide your table stracture with some data.

    Thursday, May 8, 2014 7:28 AM
  • User1713851783 posted

    Supposing that the last record in your result is "168 175 Corporate News" and not "163 175 Corporate Overview" as you report, you should try something like

    SELECT a.SubMenuId, a.Page, b.SubMenuName FROM SubMenu b INNER JOIN (
       SELECT SubMenuId, MAX(PageId) AS Page FROM DropDown GROUP BY SubMenuId
    ) a ON a.SubMenuID = b.Id

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