Reputation: 33
I'm trying to join three tables, all with the same structure. However the ID in question may or may not exist in any of the three tables.
TABLE A id name price sales
TABLE B id name price sales
TABLE C id name price sales
Each table represents the prices of a product on a given week. So TABLE A is the current week, B last week, and C the week before that.
I would post code, but honestly everything I have hasn't worked at all.
Upvotes: 0
Views: 83
Reputation: 11963
If what is needed is to select a row matching wanted_id
from any of tables A, B, or C, then:
SELECT * FROM A UNION B UNION C WHERE id=wanted_id;
Upvotes: 0
Reputation: 425033
Your database design is questionable. You should have one table for sales that has a "date" column, something like this:
PRODUCT: id name
SALES: id date product_id price sales
If you don't do that, you'll have to flush out all rows of each table every week and load in the next week... crazy.
Beyond that, your question is fairly unclear as to what you want
Upvotes: 2