Jump to content

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/234369-update-a-column-to-its-respective-value/
Share on other sites

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 ...)

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.