0

enter image description here

https://i.stack.imgur.com/kXM1A.png)

How can I transfer the data from column of one table to another table?

Table 1 (sell_products)

_____________________________________
| sale_id | product_id | qty | price |
|   3     |     11     |  24 |   6   |
_____________________________________

Table 2 (sell_list)

_________________________________________________________________
| id | user_id |     code     | client_name | quantity | amount |
|  3 |    1    | 202210070001 |    jet      |    0     |   144  |
_________________________________________________________________

I want to copy every value of qty from table 1 to table 2 quantity.

For now, I'm still trying to figure it out.

ADyson
  • 57,178
  • 14
  • 51
  • 63
Loyd
  • 1
  • 2
  • 5
    There are such things as UPDATE...SELECT and INSERT...SELECT queries. But you need to be more specific about the exact expected output, based on that sample data, in order to get more specific answers, and/or explain what you've tried so far and where you got stuck. See also [ask]. Also, why do you need/want to do this? Beware of denormalising your data...in a well-designed relational database, nothing is copied or duplicated - instead, relationships are used to allow you to join different pieces of data together when needed. P.S. I modified your tags since this is clearly a SQL issue, not PHP – ADyson Oct 28 '22 at 13:47
  • @ADyson There is no UPDATE .. SELECT in MySQL... – Akina Oct 28 '22 at 13:56
  • @Akina Well it'd be UPDATE...FROM then, presumably – ADyson Oct 28 '22 at 13:58
  • @Loyd no problem. Please provide the additional info requested, so we can help you more easily. Also it would be a lot easier for us if your sample data was provided in text/table format rather than pictures, so people can actually copy & paste it to use in answers, examples etc. Or even better, you can make us a SQLFiddle or DBFiddle live demo to work in. See also [Tips for asking a good Structured Query Language (SQL) question](https://meta.stackoverflow.com/questions/271055/tips-for-asking-a-good-structured-query-language-sql-question) for more advice on making your question easy to answer. – ADyson Oct 28 '22 at 13:58
  • @ADyson UPDATE .. FROM not exists in MySQL too... – Akina Oct 28 '22 at 14:06
  • @Akina it's like these ones, is what I mean: https://stackoverflow.com/questions/1262786/mysql-update-query-based-on-select-query . So yeah maybe the precise syntax I forgot, but you get the general idea. – ADyson Oct 28 '22 at 14:11

0 Answers0