tags:

views:

23

answers:

2

Hello there, 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

A: 

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'
Sachin Shanbhag
+1  A: 

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'
Tobiasopdenbrouw
Sachin may also be correct: I don't know off the top of my head whether you need that VALUES statement in your query.
Tobiasopdenbrouw
@tobiasopdenbrouw - actually you are right man. My query had VALUES in first line which will give syntax error. Now both our queries are same..;)
Sachin Shanbhag