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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:08:11+00:00 2026-06-14T20:08:11+00:00

I am trying to go through my users table, and if the rank column

  • 0

I am trying to go through my users table, and if the rank column is a certain value, then I want to insert a row into the messages table, with one column, “to”, being the username column from the users table, and the rest of the columns in the inserted row need to be a predefined value. I’m having trouble making this work- any help?

MySQL Configuration: (Those which are needed)

Users table:

id|username|rank

Messages table:

id|to|from|body|subject

(to needs to be from the users table, from,body,and subject need to be a predefined string

I tried to figure something out like this, but it’s not just quite all I need it to do. I got this code and modified it from another Stack Overflow question that was similar to this one.

INSERT INTO `messages` (`from`,`to`,`subject`,`body`)  
SELECT `id`,`rank`
  FROM `users`
 WHERE `rank`='Super'
  • 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-14T20:08:13+00:00Added an answer on June 14, 2026 at 8:08 pm

    You can use string literals enclosed in single quotes as column values. It is safe to intermix them with the actual column values from the rows returned by the SELECT portion of your INSERT INTO...SELECT statement.

    INSERT INTO `messages` (`from`, `to`, `subject`, `body)
      SELECT 
       /* single-quote string literals to use them in the INSERT INTO...SELECT */
       'Predefined string From',
       /* Intermixed with column values from the rows returned by the SELECT */
       `username`,
       'Predefined string subject',
       'Predefined string body'
      FROM `users`
      WHERE `rank`='Super'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of values I want to insert into a table via
I'm trying to join a Users table to my curent hasMany Through table which
I am trying to create a table where users choose which week they want
I'm trying to get all records from a table and loop through it. Pseudo
I am trying to retrieve results from a SQlite table, and then assign them
I've got users who are members of groups through a membership join table, and
The business logic is this: Users are in a Boat through a join table,
Trying to join a table fab_qouta.qoutatype to at value inside a sub query fab_status_members.statustype
I'm trying to create a table in my database through C# using the following
I'm trying to integrate custom table for authentication and role into PAS.plugin.sqlalchemy. After customisation

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.