Results 1 to 5 of 5

Thread: Does MS Access support sub-query usage

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    hongkong
    Posts
    251

    Does MS Access support sub-query usage

    All dears,

    Can I write SQL that contain sub-query for MS Access?
    Thanks

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Of course,
    Code:
    SELECT product_id, supplier_id, product_name
    FROM products
    WHERE supplier_id IN
       (SELECT supplier_id
      FROM supplier
      WHERE (country = 'USA'))
    Assuming that I want to get all products where the suplier is in US.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    hongkong
    Posts
    251
    Thanks a lot


    I wish to get the sales statistics (between start date to end date) from the database of all products. But the product name is in another table linking by oproductid, is it true to write the following:

    Code:
    Public Sub GetSalesData(ByVal StartDate As Date, ByVal EndDate As Date)
    
        sql = "SELECT Product.ProductID AS " & lProductID & ", " & _
              "Product.ProductName AS " & lProductName & ", " & _
              "SUM(OutStock.Quantity) AS " & lOutQuantity & " " & _
              "FROM Product, OutStock " & _
              "WHERE Product.ProductID=OutStock.ProductID " & " " & _
              "AND OutStock.Date BETWEEN #" & StartDate & "# AND #" & EndDate & "# " & _
              "GROUP BY Product.ProductID, Product.ProductName"
    :
    :
    Can you give me advice. Thanks again

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    The code you have looks ok, but in your case this is not a subquery, but a simple join.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    hongkong
    Posts
    251
    Originally posted by Serge
    The code you have looks ok, but in your case this is not a subquery, but a simple join.
    Yes, I originally thought of using sub-query, so asking you the question bfore. Now if this method is OK, I will choose this for simplicity. I wish to say deep thanks to yr useful help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width