查询具有多列的相同查找表 [英] Querying Same Lookup Table With Multiple Columns
本文介绍了查询具有多列的相同查找表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对此有点困惑.我有一个这样结构的数据表:
I'm a bit confused on this. I have a data table structured like this:
表格:数据
DataID Val
1 Value 1
2 Value 2
3 Value 3
4 Value 4
然后我有另一个这样结构的表:
Then I have another table structured like this:
表:表1
Col1 Col2
1 2
3 4
4 3
2 1
Table1 中的两列都指向数据表中的数据.如何让这些数据显示在查询中?例如,一个返回这个的查询:
Both columns from Table1 point to the data in the data table. How can I get this data to show in a query? For example, a query to return this:
查询:查询 1
Column1 Column2
Value 1 Value 2
Value 3 Value 4
Value 4 Value 3
Value 2 Value 1
我对 SQL 足够熟悉,可以对一列进行连接,但超出了这一点.任何帮助表示赞赏.示例 sql 或指向要阅读的内容的链接.谢谢!
I'm familiar enough with SQL to do a join with one column, but lost beyond that. Any help is appreciated. Sample sql or a link to something to read. Thanks!
PS:这是在sqlite中
PS: This is in sqlite
推荐答案
同一个表可以加入两次:
You can join the same table twice:
Select
d1.val As column1,
d2.val As column2
From table1 t
Join data d1 On ( d1.dataId = t.col1 )
Join data d2 On ( d2.dataId = t.col2 )
这篇关于查询具有多列的相同查找表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文