当前位置:Gxlcms > PHP教程 > 这样一句SQL语句应该如何写?搞了很久没有做出来

这样一句SQL语句应该如何写?搞了很久没有做出来

时间:2021-07-01 10:21:17 帮助过:17人阅读

这样一句SQL语句应该怎么写?、、搞了很久没有做出来
存在表A,字段如下:
id ident_name icon imageicon
01 黄 icon/a.jpg icon/a1.jpg
02 刘 icon/b.jpg icon/b1.jpg
03 张 icon/c.jpg icon/c1.jpg
04 李 icon/d.jpg icon/d1.jpg

存在表B,字段如下:
id friend myfriend
01 黄 刘
02 黄 张
ident_name和friend相关, 我想查询的表B黄的朋友相关资料:SQL语句怎么?//////如下
friend myfriend icon imageicon
黄 刘 icon/a.jpg icon/a1.jpg
黄 张 icon/b.jpg icon/b1.jpg



------解决方案--------------------
select b.friend ,b.myfriend , a.icon, a.imageicon from 表B b inner join 表A a on b.myfriend=a.ident_name
------解决方案--------------------
select * from A where ident_name in (select myfriend from B where friend = '黄')
------解决方案--------------------
select b.friend,b.myfriend ,(select a.icon from 表A a where a.ident_name=b.myfriend) as icon, (select a.imageicon from 表A a where a.ident_name=b.myfriend) as imageicon from 表B b where b.friend='黄'

笨方法~~,不知道效率如何。


人气教程排行