I’m trying to get data from "users" table into ‘user_id’ and ‘profile_fullname’ rows from "profiles" table.
For example if a row has an id of 1 in the "users" table, then the ‘user_id’ should also be 1.
Same with the ‘profile_fullname’.
Here’s the code:
CREATE TABLE users (
user_fullname VARCHAR(100) NOT NULL,
user_email VARCHAR(60) NOT NULL,
user_password VARCHAR(60) NOT NULL,
id SERIAL PRIMARY KEY
);
CREATE TABLE profiles (
user_id INTEGER REFERENCES users(id),
profile_fullname VARCHAR(60),
profile_headline TEXT,
profile_professional_headline TEXT,
profile_website_link VARCHAR(200),
profile_twitter_link VARCHAR(200),
profile_facebook_link VARCHAR(200),
profile_linkedin_link VARCHAR(200),
profile_youtube_link VARCHAR(200),
id SERIAL PRIMARY KEY
);
I’ve tried researching the problem, but still seems to be unclear for me how to do it.
So how can i solve it?
2
Answers
you need this one?
I assume your profiles table is empty and you are wanting to populate it with rows from the users table:
https://dba.stackexchange.com/questions/2973/how-to-insert-values-into-a-table-from-a-select-query-in-postgresql