computermax2328 Posted May 1, 2013 Share Posted May 1, 2013 Hey Guys, I am having a hard time figuring out this mysql query. So I have two tables like this. schools ---------------------------- school | town | county | full years ---------------------------- dis | location I need to insert `full` into `locations` where `school` equals `district`. Make sense? Hints would be preferred rather than answers. Quote Link to comment https://forums.phpfreaks.com/topic/277522-insert-select-where/ Share on other sites More sharing options...
requinix Posted May 1, 2013 Share Posted May 1, 2013 1. Write a SELECT to get the data you need. Make sure it only returns the `location` (and possibly `dis`?) values. 2. Stick an INSERT INTO years at the front. Might need a column list in there too, as in (location) or (dis, location). Quote Link to comment https://forums.phpfreaks.com/topic/277522-insert-select-where/#findComment-1427667 Share on other sites More sharing options...
computermax2328 Posted May 2, 2013 Author Share Posted May 2, 2013 what about the where statement?? Quote Link to comment https://forums.phpfreaks.com/topic/277522-insert-select-where/#findComment-1427674 Share on other sites More sharing options...
requinix Posted May 2, 2013 Share Posted May 2, 2013 The SELECT query retrieves all the data you want to insert into the other table; the WHERE would be part of that. Quote Link to comment https://forums.phpfreaks.com/topic/277522-insert-select-where/#findComment-1427677 Share on other sites More sharing options...
computermax2328 Posted May 2, 2013 Author Share Posted May 2, 2013 I had to do an UPDATE not an insert. I ended up with UPDATE and INNER JOIN. Thanks anyway, Quote Link to comment https://forums.phpfreaks.com/topic/277522-insert-select-where/#findComment-1427680 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.