SQL 中 INSERT INTO 查询中的多个 SELECT 语句

发布于 2024-12-14 04:20:18 字数 1118 浏览 1 评论 0原文

 INSERT INTO TextTable(Number, Tokens)  
 SELECT 
 (SELECT  ID FROM  Tureme WHERE leksem IN  
 (SELECT  Tokens FROM  Text)),
 (SELECT  Tokens FROM Text WHERE Tokens IN 
 (SELECT  leksem FROM Tureme));

TextTable 有两列->数量、代币 Tureme 有两列 -> ID(主键),leksem 和 文本有一栏 ->令牌

我的表:

TextTable 为空。

我想做的是将这些子查询的结果插入到 TextTable 中。子查询单独工作完美。但是,当我一起运行它时,它不会插入子查询的结果,并且会给出错误消息:

子查询返回超过 1 个值。当子查询跟在 =、!=、<、<=、>、>= 后面或子查询用作表达式时,这是不允许的。 该声明已终止。

我应该怎么办?


第一个子查询返回:                  第二子查询返回:

ID            &nb                        &nb            标记

4                              apple
6                              melon
9                              pear

我想用这些值填充 TextTable。

 INSERT INTO TextTable(Number, Tokens)  
 SELECT 
 (SELECT  ID FROM  Tureme WHERE leksem IN  
 (SELECT  Tokens FROM  Text)),
 (SELECT  Tokens FROM Text WHERE Tokens IN 
 (SELECT  leksem FROM Tureme));

TextTable has two columns-> Number,Tokens
Tureme has two columns -> ID(Primary Key), leksem
and
Text has one column -> Tokens

My tables:

TextTable is empty.

What I'm trying to do is inserting the results of these subqueries into TextTable. The subqueries works perfect individually. But, when I run it together, it doesn't insert results of subqueries and it gives an error saying:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

What should i do?


First subquery returns:                        Second subquery returns:

ID                                                            Tokens

4                              apple
6                              melon
9                              pear

I want to populate TextTable with these values.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花坊 2024-12-21 04:20:18

根据您的新评论,这就是您想要的 select 语句。

SELECT ID, Text.Tokens
FROM Tureme
JOIN Text ON Tureme.leksem = Text.Tokens

您需要在查询中连接表 - 否则结果不会相互关联。

Based on your new comments this is what you want for the select statement

SELECT ID, Text.Tokens
FROM Tureme
JOIN Text ON Tureme.leksem = Text.Tokens

You need to join the tables in the query -- otherwise the results don't relate to each other.

流心雨 2024-12-21 04:20:18
INSERT INTO TextTable
SELECT DISTINCT ID, Text.Tokens
FROM Tureme
JOIN Text ON Tureme.leksem = Text.Tokens

我想这正是你想要的。

INSERT INTO TextTable
SELECT DISTINCT ID, Text.Tokens
FROM Tureme
JOIN Text ON Tureme.leksem = Text.Tokens

I guess this is exactly what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文