Kevin-
SELECT BeefRecipes.RecipeTitle
FROM
(SELECT Recipes.RecipeID, Recipes.RecipeTitle
FROM (Recipes INNER JOIN Recipe_Ingredients
ON Recipes.RecipeID = Recipe_Ingredients.RecipeID)
INNER JOIN Ingredients
ON Ingredients.IngredientID =
Recipe_Ingredients.IngredientID
WHERE Ingredients.IngredientName = 'Beef')
AS BeefRecipes
INNER JOIN
(SELECT Recipe_Ingredients.RecipeID
FROM Recipe_Ingredients INNER JOIN Ingredients
ON Ingredients.IngredientID =
Recipe_Ingredients.IngredientID
WHERE Ingredients.IngredientName = 'Garlic')
AS GarlicRecipes
SELECT Products.ProductName
FROM Products
WHERE Products.ProductNumber NOT IN
(SELECT Order_Details.ProductNumber
FROM Orders INNER JOIN Order_Details
ON Orders.OrderNumber = Order_Details.OrderNumber
WHERE Orders.OrderDate
BETWEEN '2015-12-01' AND '2015-12-31');
The above query finds the products that were not ordered in the last quarter of 2015. Note that in Access, you would use # as a delimiter on the date constants instead of a single quote.
SELECT Products.ProductNumber, Products.ProductName,
(SELECT MAX(Orders.OrderDate)
FROM Orders INNER JOIN Order_Details
ON Orders.OrderNumber = Order_Details.OrderNumber
WHERE Order_Details.ProductNumber = Products.ProductNumber)
AS LastOrder
FROM Products;
The above query lists all products and the date of the latest order for that product.
What are you trying to learn? A subquery is simply a subset of data using a SELECT statement enclosed in parentheses. You can have a table subquery (multiple columns and rows), a list subquery (one column returning a value from multiple rows), or a scalar subquery (one column returning exactly one value). Using a subquery isn't dependent on the version of Access unless you go back earlier than Version 2.John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)On Apr 20, 2016, at 12:07 PM, 'zhaoliqingoffice@163.com' zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:Dear All,Can anybody upload an exmample of ms access file (2010) containing a subquery to the group? Thanks in advance.Best Regards,Kevin
Posted by: John Viescas <johnv@msn.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (4) |
Tidak ada komentar:
Posting Komentar