How should this SQL statement be written? I haven't done it in a long time.

Source: Internet
Author: User
How should this SQL statement be written? , and have been doing it for a long time.
Table A is present with 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 Zhang Icon/c.jpg Icon/c1.jpg
04 Li Icon/d.jpg icon/d1.jpg

Table B exists with the following fields:
ID friend Myfriend
01 Huang Liu
02 Huang Zhang
Ident_name and friend, I want to check the table B yellow Friends related information: SQL statement How?//////as follows
Friend Myfriend icon ImageIcon
Huang Liu Icon/a.jpg icon/a1.jpg
Huang Zhang 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 A.icon from Table A a where a.ident_name=b.myfriend) as icon, (select A.imageicon from Table A A where A.ident_name=b.myfriend) as ImageIcon from table b b where b.friend= ' yellow '

Stupid method ~ ~, do not know how efficient.


  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.