Home > Backend Development > PHP Tutorial > 这样一句SQL语句应该如何写?搞了很久没有做出来

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

WBOY
Release: 2016-06-13 11:11:35
Original
864 people have browsed it

这样一句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='黄' 

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


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template