【问题标题】:insert using sub-query and inner join使用子查询和内连接插入
【发布时间】:2013-08-02 04:38:42
【问题描述】:

我有这两张桌子。
第一个是 users_details

其次是 users_posts 表。

我想用第一列中的 username 填充列 postedby_name

我尝试了内连接和子查询的组合,但做不到。

这是我现在拥有的代码。

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

如何实现?

【问题讨论】:

    标签: mysql sql subquery inner-join


    【解决方案1】:
    Update users_posts inner join users_details  
    on users_posts.postedby = users_details.id 
    set users_posts.postedby_name=users_details.username
    

    【讨论】:

    • 没问题。我会赞成你的回答,但对SQL 的记忆不够,不知道它是否正确。
    • @SteveP。没关系,我能理解。
    • @Narendra 它有时会在你的脑海中发生,但它没有出现。你永远欢迎
    猜你喜欢
    • 1970-01-01
    • 2011-03-29
    • 2021-05-13
    • 2021-09-25
    • 1970-01-01
    • 2017-07-10
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多