help with query

  • Hello. I have two tables with a one to many relationship. The Master Table is  named Stores and the child table is named Items purchased. I have a column named date_purchased in my Stores Table. I was wondering if I wanted to get the total dollar amount for Items purchased within a date range  would I do an inner join on the two tables or do I need to also have a date_purchased column in my Items purchased table. Thanks for any help or suggestions.

  • Having a "date purchased" column in Stores doesn't make any sense, unless you were recording the date the store was purchased. Normally, if a column doesn't describe the "subject" of the table, it doesn't belong there. Purchases have purchase dates, stores don't.

  • Thanks for your comment. I thought it gave me some additional insight into design which is what I was asking for. It sounds like you are saying that I will will have a purchased_date column for every purchased_item in my table Items_Purchased. So that leads me to think that logically I will not need to add the Stores table in my query and just query the Items_Purchased Table for items purchased within a particular date range.

  • Well normally for purchases you have two tables. OrderHead and OrderLine (or whatever you call them). You would record things like the customer, tax, shipping, orderDate etc in the OrderHead. The orderLine table would record things like UPC, Price, Quantity etc. From what you are have posted it seems that your biggest challenge is that the design of your tables is less than ideal for the data you are storing.


    Need help? Help us help you.

    Read the article at for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns -
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs -
    Understanding and Using APPLY (Part 1) -
    Understanding and Using APPLY (Part 2) -

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply