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 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.

2
  • 1
    You should be using joins instead of sub-queries. Commented Nov 8, 2011 at 11:09
  • 1
    Please show some example data. Do the sub queries even return the same number of rows? How should the rows from the left hand sub query be correlated with the rows from the right? Commented Nov 8, 2011 at 11:09

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

What is the point of even submitting this answer? There's probably a 0.01% chance that this is what the OP wants (undeterministic arbitrary top expression). The "Please define your problem better" point can be made in a comment.
@MartinSmith - The point is very clear. This answer shows the OP what the compiler wants -- hopfully it will make it clear to him how to make the problem definition better or what the actual solution is. Yes it is like a comment but it is long and would have been hard to read in a comment. It could even be what he wanted to do -- since we both don't know.
I needed to Insert without duplicates. Thanks for the effort.
1
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.

1 Comment

exactly this is what I want. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.