Updating table rows from different table data not working

Updating table rows from different table data not working

I have two tables in my database. One called wp_tickets and another one called wp_tickets_regenerated.

I have two tables in my database. One called wp_tickets and another one called wp_tickets_regenerated.

I'm trying to update some of the data in the wp_tickets_regenerated table from the wp_tickets table if the lottery_id matches so i end up with a new table with different ticket_number generated for each order placed for that product.

The code I have so far is throwing up an error:

 WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM wp_tickets
        WHERE lottery_id = wp_tickets.lottery_id' at line 6 for query UPDATE wp_tickets_regenerated

Can anyone help please?

wp_tickets table

+---------+-----------+-----------+---------------+----------+------------+
| user_id | full_name | answer_id | ticket_number | order_id | lottery_id |
+---------+-----------+-----------+---------------+----------+------------+
| 0       | test      | 1         | 3             | 791      | 790        |
+---------+-----------+-----------+---------------+----------+------------+
| 0       | test      | 1         | 5             | 791      | 790        |
+---------+-----------+-----------+---------------+----------+------------+
| 0       | test      | 1         | 10            | 791      | 790        |
+---------+-----------+-----------+---------------+----------+------------+

wp_tickets_regenerated

   +---------+-----------+-----------+---------------+----------+------------+
    | user_id | full_name | answer_id | ticket_number | order_id | lottery_id |
    +---------+-----------+-----------+---------------+----------+------------+
    |         |           |           | 1             |          | 790        |
    +---------+-----------+-----------+---------------+----------+------------+
    |         |           |           | 2             |          | 790        |
    +---------+-----------+-----------+---------------+----------+------------+
    |         |           |           | 3             |          | 790        |
    +---------+-----------+-----------+---------------+----------+------------+

What i have so far is:

 $wpdb->query(
       'UPDATE wp_tickets_regenerated
        SET user_id = wp_tickets.user_id,
            full_name = wp_tickets.full_name,
            answer_id = wp_tickets.answer_id,
            order_id = wp_tickets.order_id
        FROM wp_tickets
        WHERE lottery_id = wp_tickets.lottery_id'
  );


php mysql database wordpress

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Best MySQL DigitalOcean Performance – ScaleGrid vs. DigitalOcean Managed Databases

Compare ScaleGrid MySQL vs. DigitalOcean Managed Databases - See which offers the best MySQL throughput, latency, and pricing on DigitalOcean across workloads.

PHP School Management System (PHP Web Application With MySQL Database)

School Management System In PHP (Manage Students, Teachers, Exams and Much More). This Web Application Project is build with PHP and JavaScript programming Language and MySQL Database.

PHP MySQL Tutorial - User Registration System Using PHP & MySQL

In this PHP MySQL Tutorial, you'll learn how to create a user registration and login system using PHP and a MySQL database.

How to Make Mobile Shopee using PHP and MySQL Database

In this complete E-commerce website, you'll learn how to create Mobile Shopee Using PHP and MySQL Database. We gonna start by creating an HTML template then convert it into PHP and then use MySQL database to fetch products and display it in the project.

Shopping Cart System with PHP and MySQL Database

We'll be creating a shopping cart system with PHP and MySQL Database. Using the Bootstrap card we gonna display information about the shopping cart products.