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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:45:25+00:00 2026-05-23T19:45:25+00:00

I have a query that updates a boolean value for a given record, then

  • 0

I have a query that updates a boolean value for a given record, then inserts that record into another table (depending on the action performed) using a select subquery. The select subquery is working fine, but how can I add an additional variable on to the end of the query to be inserted ? The reason why I need to do this is because the select subquery doesn’t contain this data, and this data will only be stored in one of the two tables that the original record gets “copied” to.

$id = $_POST['id'];
$action = $_POST['action'];
$reason = $_POST['reason'];
if($action == "approve") {
    $statement = $db->prepare("UPDATE waiting SET wait = :status WHERE id = :id");
    $statement->bindValue(':status', 0);
    $statement->bindParam(':id', $id);
    $statement->execute();

    $statement = $db->prepare("INSERT INTO approved (fname, lname, student_id, email, type) SELECT fname, lname, student_id, email, type FROM waiting WHERE id = :id");
    $statement->bindParam(':id', $id);
    $statement->execute();
    $lastId = $db->lastInsertId();

    $statement = $db->prepare("UPDATE approved SET reason = :reason WHERE id = $lastId");
    $statement->bindParam(':reason', $reason);
    $statement->execute();
}

Basically I want to combine the insert query that uses a select subquery and the update query that updates the reason into one query. Is this syntactically possible?

EDIT: I should be more clear and state that the reason being passed is a string entered by a user into a text field. It’s not a column or any other data in a table.

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-05-23T19:45:25+00:00Added an answer on May 23, 2026 at 7:45 pm

    You can always select a constant, and the reason value is just that from the SQL viewpoint, so you can write the insert as:

    INSERT INTO approved (fname, lname, student_id, email, type, reason) 
    SELECT fname, lname, student_id, email, type, :reason 
    FROM waiting WHERE id = :id
    

    Just bind the params then and run the query, and that’s it.

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

Sidebar

Related Questions

I have a simple SQL query that updates some date fields in a record,
I have an Update query that recalculates -every- column value in exactly one row,
I have a simple query that updates a variable column. This query is later
I have a 'stream_update' table that stores the updates users post to the groups
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I have an update query being run by a cron task that's timing out.
I have a query that is dynamically built after looking up a field list
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query that I'm executing from a .NET application to a SQL

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.