I have two tables that have a one-to-many relationship table1 (one), table2 (many).
table1 has (t1_id) as KEY
table2 has (t2_id) as KEY and t2_t1_id as as refference to table1
Now in table1 I need a column (rand_t2_id) that holds an id from table2, I do not really care which one
This is the query I tried
INSERT INTO table1 (rand_t2_id)
SELECT t2_id
FROM table2
WHERE table1.t1_id = table2.t2_t1_id;
There also needs to be a limit build in somewhere if that is needed. I only need one id from table2
No luck here tho, anyone know a fix?
IMO you could try
I assume you already have a column named
rand_t2_idon yourtable1.