gpt4 book ai didi

php - mysql联合查询

转载 作者:行者123 更新时间:2023-11-29 00:59:03 25 4
gpt4 key购买 nike

包含成员信息的表的结构如下:

   id   |    fname    |    pic    |   status
--------------------------------------------------
1 | john | a.jpg | 1
2 | mike | b.jpg | 1
3 | any | c.jpg | 1
4 | jacky | d.jpg | 1

friend 列表表如下所示:

  myid  |   date     |    user   
-------------------------------
1 | 01-01-2011 | 4
2 | 04-01-2011 | 3

我想做一个查询,结果将打印来自“friendlist”表的用户,该表包含来自“members”表的用户的照片和名称,myid(添加的人)和用户(添加的人) .

本例中的表格将如下所示:

   myid   |   myidname  |    myidpic   |  user  |  username  |  userpic  |  status   
-----------------------------------------------------------------------------------
1 | john | a.jpg | 4 | jacky | d.jpg | 1
2 | mike | b.jpg | 3 | any | c.jpg | 1

最佳答案

应该这样做:

SELECT
m1.id AS myid,
m1.fname AS myidname,
m1.pic AS myidpic,
m2.id AS user,
m2.fname AS username,
m2.pic AS userpic,
m1.status
FROM
members m1
INNER JOIN friends f ON m1.id = f.myid
INNER JOIN members m2 ON f.user = m2.id

关于php - mysql联合查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4625190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com