Marcelo Leães
Marcelo Leães

Reputation: 1

MYSQL get data from table and insert on new table with variable

I need to take the value in a table to generate a URL containing this value and insert it in a new table. Is it possible to use variables within MySQL to form this URL?

Example:

SELECT `identity_id`, `email` FROM `identities` WHERE 1

Output: 1 [email protected]

With the ID and email in hand, I need to insert the HTML content below where the respective email for each ID says VARIABLE.

INSERT INTO `identities`(`html_signature`) VALUES ([<img src="https://example.com/images/VARIABLE.png" width="580" height="138">])

Thanks for help

Upvotes: 0

Views: 29

Answers (1)

MBeale
MBeale

Reputation: 750

You can use the select into statement

INSERT INTO `identities` (`html_signatures`)
  SELECT CONCAT("<img src=\"https://example.com/images/", `email`, ".png\" width=\"580\" height=\"138\">") as html_signatures
  FROM `identities` WHERE 1

I'm not sure if VARIABLE represented the id, email, or both but you could change the concat function arguments as needed.

Upvotes: 1

Related Questions