Pradeep
Pradeep

Reputation: 1223

insert using sub-query and inner join

i have these two tables.
The first is the users_details table

Users_Details Table

Second is the users_posts table.

users_posts

i want to fill the column postedby_name with username from the first column.

I tried a combination of inner join and sub-query but could not do it.

This is the code that i have now.

update users_posts
set users_posts.postedby_name = 
(select username from users_details inner join users_posts where
users_posts.postedby = users_details.id);

How to Accomplish this.?

Upvotes: 0

Views: 330

Answers (1)

Amit Singh
Amit Singh

Reputation: 8109

Update users_posts inner join users_details  
on users_posts.postedby = users_details.id 
set users_posts.postedby_name=users_details.username

Upvotes: 4

Related Questions