I have two tables linked by a user ID. I want to create a new table from both which pulls several fields from each table. In one table there is only one row per user ID, in the other there are several rows of data for each user.
The first table is easy - all the data is in one line.
However in the second table the data is arranged in rows where each user ID has several rows. I want to find only four of these rows for each user ID and then insert these into a column in my table. This is the code below but it is not working. Can I nest sub-queries like this?
INSERT INTO new_table
select table1.ID, table1.user_email, table1.display_name, table2.meta-value (where table2.meta_key = ‘pet’), table2.meta-value (where table2.meta_key = ‘color'), table2.meta-value (where table2.meta_key = ‘location), table2.meta-value (where table2.meta_key = ‘house'),
from table_1, table2