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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:20:27+00:00 2026-06-13T21:20:27+00:00

I want to insert some values to a table (item1) from a table (item2)

  • 0

I want to insert some values to a table (item1) from a table (item2) and date which is not in that item2 table.

How do I write a SQL insert into statement using the select statement to achieve that?

eg :

INSERT into item1(date, name, qty) 
values(datevalue, select col1, col2 from item2);

This isn’t working. What should I do to fix it?

insert into daily_stock(date, product_id, name, weight, qty, free_issues, sales_price, 
                        purchased_price, category, last_purchased_date) 

     select 
        **'"+today+"'**,
        productId, name, weight, newQty, freeIssues, NewSalesPrice,
        NewPurchasePrice, category, datePurchased 
     from product

I’m using java and today is a string variable , still data is not inserting , whats wrong?

  • 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-13T21:20:28+00:00Added an answer on June 13, 2026 at 9:20 pm

    you’re almost there: just use the SELECT variation for INSERT instread of VALUES, and include your data there as a constant:

    insert into item1(date,name,qty) 
    select <datevalue>, col1, col2 from item2;
    

    If your date comes from another table, you can do this:

     insert into item1(date,name,qty) 
     select d.dcol1, i2.col1, i2.col2 
     from item2 i2 inner join table_containing_date_col d
     on <some join criteria>
    

    EDIT: you have to ensure that the data types match i.e. your has to be parsable to a date if you are savign it to a date field (which you are, hopefully!). You don’t give details of your database but it would be something like this for SQL Server

    cast('your date in yyyymmdd format' as datetime) 
    

    (yyyymmdd always works as it is recognisable ISO format)

    or better still CONVERT

    For MySql you have STR_TO_DATE, for Oracle TO_DATE etc.etc.

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

Sidebar

Related Questions

I want to insert some values from a table to another in a sql
I want to insert some values into an SQLite table. The query is: insert
I have two tables and want to insert some column values from ane table
I want to insert some data into a table (id PK autoincrement, val) with
I have the following script that I want to insert into a table, but
So, I want to insert some data into a MySQL table where the table
I want to insert some data into a table associated with dates for the
I need to create an SQL query to insert some data into a table
I want to insert some values to the table, there is an order such
I'm using a prepared statement to insert some values into my table. Before doing

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.