-
Notifications
You must be signed in to change notification settings - Fork 9
Managing Data with SQL: Exercises
In SQL Online, type the following query and click "Run":
SELECT *
FROM FOOD_NAMEWhat if we want to get only specific entries from our data? The WHERE clause can be used after the FROM clause to add conditions to what data is retrieved, like so:
SELECT *
FROM FOOD_NAME
WHERE column operator value;-
columncontains the value we want to test -
operatoris the type of comparison (e.g.,=,<,>,<=,>=) -
valueis the value we want to match (e.g., a number)
Only data where the WHERE clause is true will be retrieved.
Query from Exercise 1:
SELECT *
FROM FOOD_NAMERefine the query from Exercise 1 using a WHERE clause to SELECT only food with a FoodID of 5, i.e. FoodID = 5
Design a query to SELECT foods with FoodIDs up to _and including 7.
Design a query to SELECT foods in the poultry food group (FoodGroupID = 5), with a food source ID of 28.
Comparison operators can also be used with text, for example, using = to search for an exact text match (including capitalization):
Use the condition FoodDescription = 'Corn fritter' to SELECT only the food with the description of 'Corn fritter'