My SQL update one table, using reference from another...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've been asked to add a field to a download capture sstem I've got.
I've two tables, one that contains all the individual files info 
('single_file'), and one that records the downloads 
('completed_downloads').
All good...

I've been asked to add a file_category (article, brochure, exe etc...)
And I've gone through the 'single_file' table and added the field 
'file_cat' and populated all entries with data.
I've also added a field called 'file_cat' to 'completed_downloads' but 
they are all blank.
Both tables share a common field, called 'file_name'

What I'd like to do is:
Update all entries 'file_cat' on 'completed_downloads' taking the value of 

'file_cat' from 'single_file' where 'single_file.file_name' = 
'completed_downloads.filename'

Make sence?

Well, I've come up with this...
UPDATE completed_downloads SET file_cat = 'brochure' WHERE 
single_file.file_name = completed_downloads.file_name

but this will simply update ALL 'file_cat' to brochure, which is not what 
I want... (In fact the Query above does nothing, it doesn't work)

Now, the picture version...
I need to populate file_cat.
Hope it all makes sence?


*********************************************************************
The information contained in this e-mail message is intended only for 
the personal and confidential use of the recipient(s) named above.  
If the reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are hereby 
notified that you have received this document in error and that any
review, dissemination, distribution, or copying of this message is 
strictly prohibited. If you have received this communication in error, 
please notify us immediately by e-mail, and delete the original message.
***********************************************************************


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux