MYSQL Select from tables based on multiple rows

后端 未结 3 697
余生分开走
余生分开走 2020-12-02 01:10

I have a table called user_meta. In that table I have the following columns: ID, userID, meta_key, meta_value

3条回答
  •  粉色の甜心
    2020-12-02 02:12

    SELECT `users`.`id`, 
           `Company`.`meta_value`, 
           `UserType`.`meta_value` 
    FROM   `users` 
           JOIN `user_meta` `Company` 
             ON `Company`.`userid` = `users`.`id` 
           JOIN `user_meta` `UserType` 
             ON `UserType`.`userid` = `users`.`id` 
    WHERE  `UserType`.`meta_value` = 'staff' 
           AND `Company`.`meta_value` = 2 
    

    https://gyazo.com/de8d9124418f65b993d708c80c309325

提交回复
热议问题