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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:23:17+00:00 2026-06-14T16:23:17+00:00

I have a table with an value that I would like to be updated

  • 0

I have a table with an value that I would like to be updated periodically with a cron job. However, I need to update the value by replacing it with a value from a different table. The issue is that I would like the replacement value to be chosen randomly.

For example, Table 1 has

ID    Email
=================
1     bobatumail

Table 2 has:

ID    Email
================
1     bobatumail
2     joeatumail
3     peteatumail
4     biffatumail
5     wilneratumail
6     wilsonatumail

I would like the query to replace bobatumail in Table 1 with any of the other values in Table 2 as long as it is random. It could even be the same value as in Table 1.

Any idea how to do this?

  • 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-14T16:23:18+00:00Added an answer on June 14, 2026 at 4:23 pm

    In MySQL you could use the REPLACE statement:

    REPLACE INTO table1 (ID, Email)
    SELECT 1, table2.Email FROM table2 ORDER BY RAND() LIMIT 1;
    

    The “1” in the second line represents the id of the entry while the second part returns a random value out of table2. Yes, there are solutions using the UPDATE statement (JOIN and ANSI) but its always tricky and you usually have to turn off safe update mode.

    http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html#option_mysql_safe-updates

    Please note that REPLACE first deletes the old entry and then reinserts the new one.

    http://dev.mysql.com/doc/refman/5.5/en/replace.html

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

Sidebar

Related Questions

I have a table that looks like this: id value AGA 0.211 AGA 0.433
I have a table that looks something like this: Name Year Value A 2000
I have the trigger in one table and would like to read UserId value
We have a table value function that returns a list of people you may
I have a DB table that already has an existing value that I don't
I have a value that increases by 1 every 5 views. The MySQL table
I have a table that have sigh in and sign out value **id Date
I have a table with string values that need to matched individually to a
I have an html table containing values that are being generated from javascript. How
I have a multi-row insert that looks something like: insert into table VALUES (1,

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.