How should I write such an SQL statement? I haven't done it for a long time.
Source: Internet
Author: User
How should I write such an SQL statement? . Table A has not been created for A long time. the fields are as follows: id & nbsp; ident_name & nbsp; & nbsp; icon & nbsp; how should I write such an SQL statement? , Has not been made for a long time
Table A has the following fields:
Id ident_name icon imageicon
01 yellow icon/a.jpg icon/a1.jpg
02 Liu icon/B .jpg icon/b1.jpg
03 icon/c.jpg icon/c1.jpg
04 Li icon/d.jpg icon/d1.jpg
Table B exists. The fields are as follows:
Id friend myfriend
01 Huang Liu
02 Huang Zhang
Ident_name is related to friend. I want to query related information about Table B yellow: What is the SQL statement? /// // As follows
Friend myfriend icon imageicon
Huang Liu icon/a.jpg icon/a1.jpg
Yellow icon/B .jpg icon/b1.jpg
------ Solution --------------------
Select B. friend, B. myfriend, a. icon, a. imageicon from Table B B inner join table A a on B. myfriend = a. ident_name
------ Solution --------------------
Select * from A where ident_name in (select myfriend from B where friend = 'yellow ')
------ Solution --------------------
Select B. friend, B. myfriend, (select. icon from table A a where. ident_name = B. myfriend) as icon, (select. imageicon from table A a where. ident_name = B. myfriend) as imageicon from Table B B where B. friend = 'yellow'
Stupid method ~~, I don't know how efficient it is.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service