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 7673487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:31:22+00:00 2026-05-31T16:31:22+00:00

need help/guide for sql select query, I have 2 table stock and stock_history, in

  • 0

need help/guide for sql select query, I have 2 table stock and stock_history, in stock will have initial values for stock
and before update the stock table,stock_history will be inserted 1st from stock table, my case is need to get status of stock based on selection date,
this is to track open stock balance and close stock balance, close stock balance is easy where just need to fetch data from table stock
for particular timestamp, but the critical part is when to fetch data for open stock balance where need trace the status for specific timestamp,
this only can be done by refering the history table, so i need the sql where need to select data from both stock and stock_history

status table
id  desc
--  ----
01  consignment
02  customer
03  bank
04  safekeep
05  exit

stock
-----
ref_no   serial_no      status  timeStamp
1        001            04        2012-03-01 09:03:00

stock_history
-------------
ref_no   serial_no  status  timeStamp
1        001        01      2012-03-01 09:00:00
1        001        03      2012-03-01 09:01:00
1        001        02      2012-03-01 09:02:00

 so, when choose for date 
 01/03/12 time 9:01   =   1    001  03  2012-03-01 09:01:00
 01/03/12 time 9:01   =   1    001  03  2012-03-01 09:01:00

please help, thanks in advance

  • 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-05-31T16:31:23+00:00Added an answer on May 31, 2026 at 4:31 pm

    You can use the UNION operator to select from multiple tables:

    SELECT * FROM stock
    UNION ALL
    SELECT * FROM stock_history
    WHERE ...
    

    That said, I’d suggest restructuring your schema. Why have a separate “stock” and “stock_history” table? You really only need one “stock” table to store both — the “current” stock is just the one with the highest status. Or you could even be explicit and maintain an “is_current” flag row.

    Update: Changed UNION to UNION ALL. The ALL means just combine the rows for both tables, no extra processing. Leaving it off will attempt to remove any duplicate rows first, which could be less efficient (and makes no difference in the results here since duplicates are not possible with your schema). Hat tip to @SmartestVEGA.

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

Sidebar

Related Questions

need help regarding USSD Gateway. I have to develop an app, which will directly
need help in error in database pivot. i have table tamed table_score like below:
I need help with custom url in MVC3. I have a news table and
I need help with wordpress. I will show a login box on my main
I have a SQL Server table that contains the following fields: SessionId (guid) Message
Hi Guys i need some help with Jquery Validadion Plugin I have an input
I need help with my PHP code, as I have a project where I
I need some help for iphone application,i have some question regarding the new iOS
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
Need help writing a script downloads data from google insight using c# this is

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.