Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9038765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:34:00+00:00 2026-06-16T09:34:00+00:00

I have 3 tables (see below), Table A describes a product, Table B holds

  • 0

I have 3 tables (see below), Table A describes a product, Table B holds inventory information for different dates, and Table C holds the price of each product for different dates.

 Table A
 ------------------
 product_id    product_name
 1             book
 2             pencil
 3             stapler
 ...           ...

 Table B
 ------------------
 product_id    date_id     quantity
 1             2012-12-01  100
 1             2012-12-02  110
 1             2012-12-03  90
 2             2012-12-01  98
 2             2012-12-02  50
 ...           ...         ...

 Table C
 -------------------
 product_id   date_id      price
 1            2012-12-01   10.29
 1            2012-12-02   12.12
 2            2012-12-02   32.98
 3            2012-12-01   10.12

In many parts of my java application I would like to know what the dollar-value of each of the product is so I end up doing the following query

 select 
      a.product_name,
      b.date_id,
      b.quantity * c.price as total
 from A a
 join B b on a.product_id = b.product_id
 join C c on a.product_id = c.product_id and b.date_id = c.date_id
 where b.date_id = ${date_input}

I had an idea today that I could make the query above be a view (minus the date condition), then query the view for a specific date so my queries would look like

 select * from view where date_id = ${date_input}

I’m not sure where the appropriate level of abstraction for such logic is. Should it be in java code (read from a pref file), or encoded into a view in the database?

The only reason I don’t want to put it as a view is that as time goes by the join will become expensive as there will be more and more dates to cover, and I’m usually only interested in the past month’s worth of data. Perhaps a stored proc is better? Would that be a good place to abstract this logic?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:34:02+00:00Added an answer on June 16, 2026 at 9:34 am

    If views are implemented correctly you should never see worst performance in a case like this where the query would be the same without the view. More dates will not affect the performance because you have this view.

    Make the view, it is the correct abstraction in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two database tables below: Course_Module Table: CourseId ModuleId 1 1 1 2
I have got 3 tables in my database. Company, Product and Lead. Below are
I have an Entity called Product, this entity, through table mapping, merges 6 tables
I want to compare fields in 2 tables to see if the fields have
I have a couple of questions. 1) Why cannot we see system tables (like
Sorry for a pretty specific question. I have a table (see bottom), and when
I have an application that has a status table see Database best practices -
I have a table. see my table structure <table width=100% border=1> <tr> <td width=2%><h2>#
see fiddle i have html table and one textbox and one button.make cell selection
see jsbin if u seen my jsbin then i have two table hardcode table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.