Click here to Skip to main content
16,020,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii,
i have table:
1)contents: contentID,
contenttext

2)Sentence: SentenceID,
sentenceText

3)ContentSentences:contentID,
SentenceID,
orderno

i want to insert ContentID & SentenceID into ContentSentences table. this coloum are in content & sentence table for that i have write query.

i have write query:
INSERT INTO ContentSentences(SELECT ContentID FROM Contents) UNION (SELECT SentenceID FROM Sentences)
but it shows me error. how can i do it?
Posted
Updated 26-Feb-15 23:36pm
v2
Comments
Peter Leow 27-Feb-15 5:53am    
How do the contentID and sentenceID related in the ContentSentences table?
vatsaldesai 27-Feb-15 6:01am    
WITH PRIMARY KEY & FORIENGE KEY RELATION SHIP... Contentsentece table relate with contents using contentID & same as for sentence table.
What is that error?
vatsaldesai 27-Feb-15 7:30am    
its not working giving me error:he select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.
Can you please try to write query? that insert contentid & sentenceid into contentsentece table.its means i want copy contentid data into contentsentece table and same as sentenceid.
i have write another query:
insert into ContentSentences(ContentID,SentenceID)
select ContentID from Contents
union
select SentenceID from Sentences; this give me error as above menstion
ZurdoDev 27-Feb-15 8:02am    
The error is very clear, isn't it? You are not inserting enough values into the columns.

Write it this way instead:

INSERT INTO ContentSentences (field1)
SELECT ContentID FROM Contents

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900