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. 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). 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?? 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. 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, Link to comment https://forums.phpfreaks.com/topic/277522-insert-select-where/#findComment-1427680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.