0

I have the following SQL query:

INSERT INTO site_city_address (`cityName`, `cityCode`, `stateId`) VALUES (SELECT a.city, a.cityCode, b.stateId FROM site_address_dropdown a INNER JOIN site_state_address b ON a.state = b.stateName); 

I know it's possibly wrong. What I want to do is to insert the values of a.city, a.cityCode, and b.stateId as cityName, cityCode, and stateId into the shopious_city_address. How do I do so?

2 Answers 2

3

You can specify values or select after an insert. In your case, omit values:

INSERT INTO site_city_address (`cityName`, `cityCode`, `stateId`) SELECT a.city, a.cityCode, b.stateId FROM site_address_dropdown a INNER JOIN site_state_address b ON a.state = b.stateName; 
Sign up to request clarification or add additional context in comments.

Comments

1

remove the VALUES keyword. INSERT INTO...SELECT has the following syntax,

INSERT INTO site_city_address (cityName, cityCode, stateId) SELECT a.city, a.cityCode, b.stateId FROM site_address_dropdown a INNER JOIN site_state_address b ON a.state = b.stateName 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.