dtdfj08626 2017-03-27 14:02 采纳率: 0%
浏览 87

Mysql select任意一行FROM table_one具有相同值的WHERE列多次出现,然后从一个数组中的table_two输出它们的数据

Doesn't matter how many times a user_id appears in table_one, I just need select any of their user_ids e.g select any of (user_id = 8 and user_id = 12) then get their names and age from table_two then add them into an array. Here are the tables:

table_one:

id   user_id   user_loves
1      8       Mango
2      5       Apple
3      1       Oranges
4      12      Toys
5      8       Guns
6      12      Bats

table_two:

id   user_id    name      Age
 1      8       David     19
 2      5       Michael   24
 3      12      Elsa     22
 4      4       Greg      26

Get any of user_id = 8 AND user_id = 12; then fetch the corresponding names and age from table_two and populate the result into an accessible array like so:

$result = array();
firstname = $result[0][name];
second_age - $result[1][age];

So that my final answer is

firstname = David
secondName = Elsa
second_age = 22
  • 写回答

1条回答 默认 最新

  • doukuang6795 2017-03-27 14:06
    关注

    you could use a select distinct and left join

    select distinct t1.user_id, t2.name,  t2.age 
    from table_one t1
    left join table_two t2 on t1.user_id = t2-user_id 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集