【问题标题】:Linking an ID in one table to the ID for multiple fields in another table将一个表中的 ID 链接到另一表中多个字段的 ID
【发布时间】:2015-08-28 05:53:25
【问题描述】:

基本上,我有一个用户名的唯一 id 表。然后我有一个向用户询问多个问题的 html 表单。我想将我的唯一 ID 链接到存储问题的表,例如“问题”。在“问题”中,我想将问题的 ID 链接到用户名的唯一 ID。例如,问题 1,2,3,4,5 的 ID 为 1,1,1,1,1 用于用户名“Bob”。我怎样才能做到这一点?我一直在努力编写查询并搜索了多个来源,但没有运气。感谢您的帮助

【问题讨论】:

    标签: mysql webforms linker matching


    【解决方案1】:

    假设您有以下架构

    users
    -----
    + id
    - name
    
    questions
    ---------
    + id
    - user_id
    - question_txt
    

    使用这个查询

    SELECT u.id, u.`name`, q.id as 'question_id', q.question_txt
    FROM
        users u
        INNER JOIN questions q ON u.id=q.user_id
    

    【讨论】:

      猜你喜欢
      • 2013-02-20
      • 2011-06-07
      • 1970-01-01
      • 2013-05-21
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多