I want to create menu with sub menus. Therefore all I need to do is display menu_cat
as Main menu (Not repeating) while menu
be the sub menu for related menu_cat
.
Clauses like DISTINCT and GROUP BY appear to work on entire rows. As a result of my search , I came across this link: DISTINCT for only one Column
This is exactly what I'm trying to do. However I'm getting error. Below is my query and Phpmyadmin error. Please help me to fix this error.
$query = "Select * FROM ('SELECT menu_cat,menu,manu_href,ROW_NUMBER() OVER(PARTITION BY menu_cat ORDER BY menu_id DESC) rn FROM menu')a WHERE rn = 1";
Error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''SELECT menu_cat,menu,manu_href,ROW_NUMBER() OVER(PARTITION BY menu_cat ORDER BY' at line 1
$query2 = "select menu_cat OVER (PARTITION BY menu_id) AS Cat,menu,menu_href from menu"
Error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY menu_id) AS Cat,menu,menu_href from menu LIMIT 0, 30' at line 1