| 196 | 1. View My Food Orders |
| 197 | \\ |
| 198 | This SQL statement selects the order_id, order_date, status, and the total price from the ''order'' table together with the ordered items from the ''order_items'' table and their names from the ''item'' table. A join is made between ''order_items'', ''item'', and ''order''. It filters only the orders of the user with user_id = 1 and displays them ordered by date (order_date) in descending order (newest first). |
| 199 | \\ |
| 200 | {{{#!td |
| 201 | SELECT |
| 202 | o.order_id, o.order_date, o.status, |
| 203 | i.name AS item_name, oi.quantity, oi.total_price |
| 204 | FROM "ORDERS" o\\ |
| 205 | JOIN ORDER_ITEMS oi ON o.order_id = oi.order_id\\ |
| 206 | JOIN ITEM i ON oi.item_id = i.item_id\\ |
| 207 | WHERE o.user_id = 1\\ |
| 208 | ORDER BY o.order_date DESC; |
| 209 | }}} |
| 210 | 2. Manage Restaurant's Menu |
| 211 | This SQL statement selects all items item_id, name, price and description of a given restaurant. A join is made between the ''menu'' table and the ''item'' table through item_id. It filters by restaurant_id = 2 to show only the menu for that restaurant. |
| 212 | |
| 213 | {{{#!td |
| 214 | SELECT |
| 215 | i.item_id, i.name, i.price, i.description, i.image_url |
| 216 | FROM MENU m\\ |
| 217 | JOIN ITEM i ON m.item_id = i.item_id\\ |
| 218 | WHERE m.restaurant_id = 2\\ |
| 219 | ORDER BY i.name ASC;\\ |
| 220 | }}} |
| 221 | 3. Track Order Status |
| 222 | This SQL statement selects the order_id, order_date, status, and the restaurant name from which the order was placed. A join is made between the ''order'', ''restaurant'', and ''restaurant_owners'' tables. It filters for the order with order_id = 1. |
| 223 | {{{#!td |
| 224 | SELECT |
| 225 | o.order_id, o.order_date, o.status, r.name AS restaurant_name |
| 226 | FROM "ORDERS" o |
| 227 | JOIN RESTAURANT r ON o.address_id = r.address_id |
| 228 | JOIN RESTAURANT_OWNERS ro ON r.restaurant_id = ro.restaurant_id |
| 229 | WHERE o.order_id = 1; |
| 230 | |
| 231 | }}} |