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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:57:07+00:00 2026-06-09T14:57:07+00:00

Is following insert based on select on one of the column possible in MySQL

  • 0

Is following insert based on select on one of the column possible in MySQL

INSERT INTO student_fees(id, name, fees) 
VALUES(1, SELECT name from students where student_id = 1, 200$) 

If yes then and example will really help.

-Thanks

  • 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-09T14:57:08+00:00Added an answer on June 9, 2026 at 2:57 pm

    Try INSERT...SELECT statement

    INSERT INTO student_fees(id, name, fees) 
    SELECT ... -- put here the SELECT STATEMENT with condition
    

    if your column ID is auto incremented, you don’t have to specify the 1 or else it will cause you an error.

    INSERT INTO student_fees(name, fees) 
    SELECT `name`, '200$' 
    FROM students         -- this will select all students on the table
                          -- and add $200 on thier fees.
    

    Another point is, if you only want to insert one column from the student‘s table, you need yo specify the condition, so you will not get constraint error (assuming your column ID is the Primary Key)

    INSERT INTO student_fees(name, fees) 
    SELECT `name`, '200$' 
    FROM   students
    WHERE  columnName = 'blahBlah'
    

    UPDATE 1

    Seeing your comment, you have this query

    INSERT INTO coupon_allotment (page_id, offer_id, coupon_code, user_id) 
    SELECT page_id, 4, 'ABC'        -- number of columns mismatch, right?
    FROM pages_discounts_association 
    WHERE discount_id = 4
    

    you need to remove the user_id column above OR you need to add an ID in your select statement in order to match the number of columns.

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

Sidebar

Related Questions

I'm using the following query: INSERT INTO role (name, created) VALUES ('Content Coordinator', GETDATE()),
I am trying to execute following query: Insert into pligg_links_temp select * from pligg_links
Considering the following TSQL: INSERT INTO Address(Street1, City, State, ZipCode) SELECT Street1, City, StateCode,
I have the following query: INSERT INTO table (a, b, c) VALUES (NOW(), NOW()
I'm using the following to insert company data into a mysql table. Is is
If I insert the following values into my table Insert into Table1 (Field1, Field2,
I have the following INSERT statement: INSERT INTO [StoreTestDB].[dbo].[KitItem] ([KitItemGUID] ,[KitGroupID] ,[Name] ,[Description] ,[PriceDelta]
Is there anyway to link one value to another based on it's column name?
I am getting an error in the following query: insert into ProductStone ( Pieces,
I want to insert the following include tag into my webpage using JavaScript. <!--#include

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.