1

what is wrong with this query?

INSERT INTO table1 VALUES id, pic0, pic1, pic2, pic3, pic4 FROM table2 WHERE condition1 = 'cond1' AND condition2 = 'cond2' AND age = '18' AND ( weight = '100 - 115 lbs' OR weight = '115- 130 lbs' ) AND hairlength <> 'short'

Conditions are for table2. I want to insert into table 1 just the rows from table two which meet the conditions set my me after WHERE clause.

Thank u

2 Answers 2

2

I think you want:

INSERT INTO table1 (id, pic0, pic1, pic2, pic3, pic4)
SELECT id, pic0, pic1, pic2, pic3, pic4
FROM table2
WHERE condition1 = 'cond1' 
AND condition2 = 'cond2' AND age = '18' 
AND ( weight = '100 - 115 lbs' OR weight = '115- 130 lbs' )
AND hairlength <> 'short'
Sign up to request clarification or add additional context in comments.

2 Comments

Sachin may also be correct: I don't know off the top of my head whether you need that VALUES statement in your query.
actually you are right man. My query had VALUES in first line which will give syntax error. Now both our queries are same..;)
0

try this -

INSERT INTO table1 (id, pic0, pic1, pic2, pic3, pic4)
select id, pic0, pic1, pic2, pic3, pic4  
FROM table2 WHERE condition1 = 'cond1' AND condition2 = 'cond2' 
AND age = '18' AND ( weight = '100 - 115 lbs' OR weight = '115- 130 lbs' ) 
AND hairlength <> 'short'

Comments

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.