I am building an app 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? Can
anyone offer a better way to make this work? 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
itemName, item description, price (if item has subCategory equal
to zero)
subCategory
itemName, item description, price
subCategory
itemName, item description, price
Repeat until all items in the query have been printed.
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? Can
anyone offer a better way to make this work? 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
itemName, item description, price (if item has subCategory equal
to zero)
subCategory
itemName, item description, price
subCategory
itemName, item description, price
Repeat until all items in the query have been printed.
Comment