Last post Nov 09, 2017 07:43 AM by Deepak Panchal
Nov 09, 2017 03:02 AM|rkrex|LINK
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.
Nov 09, 2017 07:43 AM|Deepak Panchal|LINK
you did not posted the whole table design so below is a general example.
SELECT title, pub_name
FROM titles INNER JOIN
publishers ON titles.pub_id = publishers.pub_id
you can see that both tables contains the pub_id field and you can fetch the value if the pub_id is same from both the table.
so in your table you need to create a common field based on that you can fetch the value using join.
refer link below to get more examples of other joins.
Types of Joins
you had asked to create date_purchased column in both tables as a common column.
here, I want to suggest you that try to follow the database designing rules and properly design your database.
if you store the date with in both tables then you are storing the duplicate values.
you can consider to create id field as common field between these two tables.
11 important database designing rules which I follow