[英]Map results from one table to different columns in another query
I'm trying to retrieve a set of records from table that has descriptions on another table in same database.我正在尝试从表中检索一组记录,该表在同一数据库中的另一个表上有描述。
Table 1:表格1:
ColA1 | ColA1 | DescrpA1描述A1
-- A - - - - Apple - 一个苹果
-- B - - - - Orange -- B - - - - 橙色
-- C - - - - Banana -- C - - - - 香蕉
-- D - - - - Watermelon -- D - - - - 西瓜
Table 2:表 2:
ColA2 | ColA2 | Qty1 |数量1 | ColB2 | ColB2 | Qty2 |数量2 |
--A - - - - - 1 - - - C - - - - 1 --A - - - - - 1 - - - C - - - - 1
--C - - - - - 1 - - - D - - - - 2 --C - - - - - 1 - - - D - - - - 2
--B - - - - - 1 - - - A - - - - 1 --B - - - - - 1 - - - A - - - - 1
What I want is a way to map descriptions from Table1 into results of Table2我想要的是一种将表1中的map描述转换为表2结果的方法
Sorry about the formatting.对不起格式。 first time posting a questi第一次发布问题
You want to join
the tables.你想join
表格。 . . . . twice:两次:
select t2.cola2, t1_a.DescrpA1, t2.colb2, t1_b.DescrpA1
from table2 t2 join
table1 t1_a
on t2.cola2 = t1_a.cola1 join
table1 t1_b
on t2.colb2 = t1_b.cola1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.