One-to-Multiple SQL statement syntax for fields between SQL SERVER tables and tables, serversql

Source: Internet
Author: User

One-to-Multiple SQL statement syntax for fields between SQL SERVER tables and tables, serversql

Table

A1 A2 A3 A4
01 02 03 04
03 04 01 02

Table B

B1 B2
01 Zhang San
02 Li Si
03 Wang Wu
04 Zhao Liu

Display result

A1 A2 A3 A4
Zhang San Li Si Wang Wu Zhao Liu
Wang Wu Zhao Liu Zhang San Li Si

:

The SQL statement is as follows:

SELECT  (SELECT B2 FROM B WHERE B1=A1) AS A1, (SELECT B2 FROM B WHERE B1=A2) AS A2, (SELECT B2 FROM B WHERE B1=A3) AS A3, (SELECT B2 FROM B WHERE B1=A4) AS A4 FROM A 

So OK.

Related Article

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.