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'
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
SELECTportion of yourINSERT INTO...SELECTstatement.