I am building an app and need some assistance with constructing an SQL query. My app is for a restaurant. The restaurant has multiple menus. When the user comes to a page for a specific menu I need to pull all item data from multiple database tables. There are multiple categories of items, each item falls under a category. Some categories have items that fall into sub categories.
I posted my database tables and a basic sample of the output below. I know how to do this and it is easy if I create one huge table, but due to the amount of data I am working with I need to make sure that this is put together as efficiently as possible.
Is it possible to combine all of this into one SQL statement? Any thoughts would be greatly appreciated. Thanks in advance.
I have three tables:
items
itemId (key)
itemName
itemDescription
price
menu
category
subCategory (could be '0' if item does not have subCategory)
menus
menuId (key)
menuName
menuDescription
menuCategories
categoryId (key)
category
menu
description
menuSubCategory
subCategoryId (key)
subCategory
menuId
categoryId
I want to print the output on the page in the following format:
Category
[INDENT]itemName, item description, price (if item does not have subCategory)[/INDENT]
[INDENT]subCategory[/INDENT]
[INDENT][INDENT]itemName, item description, price[/INDENT][/INDENT]
[INDENT]subCategory[/INDENT]
[INDENT][INDENT]itemName, item description, price[/INDENT][/INDENT]
Repeat until all items in the query have been printed.