1

I’m new to MySQL and I have been given a task to do which to me is quite advanced.

There are 3 tables. 1st table contains the user information (users). The second table also contains the user information with the name of the state they are from (staff). While the 3rd table contains the state id and the state name (states). I’m tasked with populating the first table, the user table with state_id (from the states table) for each user. How do I go about this, since information is needed from the second table to know what state id to put in the first table?

styles9
  • 23
  • 3
  • 9

2 Answers2

1

You write to each table in the order that works. So if you need something from another table first, do that first.

Try reading through something like Insert Into Multiple Mysql Tables With One-to-one Relationship or Google it.

Zoe Edwards
  • 12,999
  • 3
  • 24
  • 43
0

Well, to obtain more clear answer you need to ask more clear question. How the tables look like precisely? Some schema could help.

I think you could use update together with join as is described here for example.

Aleš Zrak
  • 603
  • 2
  • 10
  • 19