Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

insert using where clause.

INSERT INTO table1 where userid = 419

select store from table2

how can I select from one table and insert into another but using a where clause in the insert statement. this way it will only insert where the userid is 419
Avatar of HomerTNachoCheese
HomerTNachoCheese

I am assuming both table1 and table2 both have a field called store.  If table1 is using a different field name, change store in the first line to whatever that field name is.

You may need to change 419 to '419'

INSERT INTO [table1] ( store )
SELECT table2.store
FROM table2
WHERE (((table2.userid)=419))
Avatar of santhimurthyd
I'm not clear on your question, but below Syntax will help up to insert record of userid = 419 from table2 to table1

INSERT INTO table1
select store from table2 where userid = 419
Avatar of Seven price

ASKER

well table2 I need to select all stores and insert them into table 1 but table 1 has multiply stores so I must insert all stores but insert them with row value 419

example

table 1

userid   storeid
419        store1
419        store2
419        store3
419        store4

table2 where I need to select all stores is just
storeid
store1
store2
store3
store4
ASKER CERTIFIED SOLUTION
Avatar of HomerTNachoCheese
HomerTNachoCheese

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
work great
I had a typo in that last one, glad you figured it out!