Zane Posted April 21, 2011 Share Posted April 21, 2011 I got a MySQL situation here that I'm wondering if it has a simple solution before I got all manual labor data entry on it. At the moment, I have three tables... - defects - id (int) - name (varchar) - pallets - id (int) -a bunch of other pallet related fields - defected - id (int) - defect (int) - pallet (int) As you can see, that third table is a joining table for pallets with multiple defects. My problem now is that apparently I didn't have to go through all this multiple defect stuff because a pallet can only have one. My question is... Is there a simple query where I can Select the pallet id and defect id from defected... and use those to update a new defect column I'm gonna put into the pallets table? Quote Link to comment https://forums.phpfreaks.com/topic/234369-update-a-column-to-its-respective-value/ Share on other sites More sharing options...
requinix Posted April 21, 2011 Share Posted April 21, 2011 FYI: you can do JOINs and such with UPDATE queries. After making sure there is, in fact, only one defect per pallet (and after adding the defect name column to the pallets table), you can do a subquery. Not the most efficient thing ever, but it's quick to write, and it's not like you'll be doing this ever again so... UPDATE pallets SET defect = (SELECT ...) Quote Link to comment https://forums.phpfreaks.com/topic/234369-update-a-column-to-its-respective-value/#findComment-1204612 Share on other sites More sharing options...
Zane Posted April 22, 2011 Author Share Posted April 22, 2011 Yeah,.. I did think of that later. Taking the first, last or middle as the default in the sql trickery .... process, but in the end I persuaded the client to delete all the entered items and start from scratch. It seemed the easiest way to reset a database schema, especially when there were only 23 rows. Quote Link to comment https://forums.phpfreaks.com/topic/234369-update-a-column-to-its-respective-value/#findComment-1204718 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.