查询具有多列的相同查找表

编程入门 行业动态 更新时间:2024-10-26 22:30:52
本文介绍了查询具有多列的相同查找表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对此有点困惑.我有一个这样结构的数据表:

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 )

更多推荐

查询具有多列的相同查找表

本文发布于:2023-10-19 18:20:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508364.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有多

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!