473,395 Members | 1,688 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,395 software developers and data experts.

Update field with identically named field from another table

I am having two tables, table A has the following fields:
cust_ID, email
Table B has the following fields:
ID, email, name
I want to move email from Table A to B when the cust_ID = ID.
Please notice that both tables are filled with the same ids..

Anyone can help with my sql statment for this
Mar 10 '08 #1
7 1403
ronverdonk
4,258 Expert 4TB
Welcome to The Scripts!
Expand|Select|Wrap|Line Numbers
  1. update B set email=(select email from A where A.Cust_id=B.Id);
That will do it.

Ronald
Mar 10 '08 #2
ronverdonk
4,258 Expert 4TB
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR
Mar 10 '08 #3
Welcome to The Scripts!
Expand|Select|Wrap|Line Numbers
  1. update B set email=(select email from A where A.Cust_id=B.Id);
That will do it.

Ronald
Having this error
--------------------------------------------------------------------------------
Error

SQL query: Documentation

UPDATE B SET email = ( SELECT email
FROM A
WHERE A.Cust_id = B.ID )

MySQL said: Documentation
#1242 - Subquery returns more than 1 row
---------------------------------------------------------------------------------
Mar 10 '08 #4
ronverdonk
4,258 Expert 4TB
So table A has duplicates, yes?

Ronald
Mar 10 '08 #5
So table A has duplicates, yes?

Ronald
Table A have the ids stored.. I want to add the emails to those ids when it matches the table B ids
Mar 10 '08 #6
amitpatel66
2,367 Expert 2GB
Table A have the ids stored.. I want to add the emails to those ids when it matches the table B ids
Your table A contains more than one record for particular ID because of which it is throwing that error. So with which EMAIL ID you need to perform an UPDATE?? You can use AGGREGRATE function if that satisfies your requirement else try with EXISTS clause.
Mar 10 '08 #7
ronverdonk
4,258 Expert 4TB
Table A have the ids stored.. I want to add the emails to those ids when it matches the table B ids
That I know. But what when your table B has more rows with an identical ID, which one must then be inserted into A??

Ronald
Mar 10 '08 #8

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

Similar topics

8
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
1
by: Tony Johnson | last post by:
I want to update a particular field in a form for only a certain set of records. The certain set of records is named Financed. I need to update those Financed records with a financed number that...
3
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of...
3
by: Tony | last post by:
Hello, I have a form that has a field that needs to be updated from data on another table. The field that needs updating is named RFF #. The table that contains the data is in...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
4
by: | last post by:
Given an XML file (dataset.writexml), here is my output (simplified for this posting): <?xml version="1.0" standalone="yes"?> <NewDataSet> <Category> <CategoryId>80</CategoryId>...
4
by: hapnendad | last post by:
In the question statement below Field names are in and variables are in (). All fields referenced are in what I have named the ‘PAR’ Table. Using MS Access 2003, I am working on a project...
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: 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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.