473,382 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Normalizing with Update

164 Expert 100+
Hello, I have run into an issue and need someone to explain a process to me in laymen's terms so I can understand it.

I have two [hypothetical] tables in MS Access. They are define thus:

Expand|Select|Wrap|Line Numbers
  1. Table: Products
  2.  
  3. ID      Name    Customer
  4. -------+-------+-------
  5. 1       Pants   Bob
  6. 2       Shirt   Henry
  7. 3       Shoes    Dad
  8. 4       Socks   Dad
  9. 5       Apple   Henry
  10. 6       Banana  Henry
  11. 7       Orange  Henry
  12.  
  13. Table: Customers
  14.  
  15. ID      Name 
  16. -------+-------
  17. 1       Bob
  18. 2       Henry
  19. 3       Dad
  20. 4       Jacob
  21.  
Please help me understand the SQL statement I could write in order to update 'Products' by replacing the data in the Customer column with the data in the ID column of 'Customers' which corresponds.
Apr 15 '09 #1
4 1257
FishVal
2,653 Expert 2GB
Something like the following:
Expand|Select|Wrap|Line Numbers
  1. UPDATE Products INNER JOIN Customers ON Products.Customer = Customers.Name SET Products.CustomerID = Customers.ID;
  2.  
where Products.CustomerID is a new field with a relevant datatype (I guess Products.Customer and Customers.ID datatypes don't match)
Apr 15 '09 #2
NeoPa
32,556 Expert Mod 16PB
First add a new field into your Products table called CustomerID. This would be of the same type as the [ID] field already in the Customers table, except that if Customers.ID is an AutoNumber field, CustomerID would have to be set as Long Integer.

That done, you would use SQL very similar to (identical with really) that which Fish has supplied already :
Expand|Select|Wrap|Line Numbers
  1. UPDATE Products INNER JOIN Customers
  2.     ON Products.Customer=Customers.Name
  3. SET    Products.CustomerID=Customers.ID
Apr 15 '09 #3
Nicodemas
164 Expert 100+
Delicious, thank you!
Apr 16 '09 #4
NeoPa
32,556 Expert Mod 16PB
You're welcome :)

Anyone looking to normalise existing data is worth supporting as far as I'm concerned.
Apr 16 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
0
by: Evan Escently | last post by:
Hi, I've laid out a _very_ simple database that tracks my artwork the table 'works' looks like: +---------+----------+------------+------------+-------------+ | work_id | title | media ...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
27
by: VK | last post by:
<http://www.jibbering.com/faq/#FAQ3_2> The parts where update, replacement or add-on is needed are in <update> tag. 3.2 What online resources are available? Javascript FAQ sites, please...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: Megan | last post by:
hello everybody- i'm normalizing a database i inherited. i'm breaking up a huge table named case into several smaller tables. i am creating several many to many relationships between the new...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
8
by: Richard Hollenbeck | last post by:
I have a recipe database that I've been building but I haven't yet put any of the ingredients in because of a little problem of normalization. If I build a table of ingredients, all the recipes...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.