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

Update using a specific record

32
Hi,

I have a table called 'Countries' with country codes, and other related attributes.

Countries
id country_code full_name rate

I have another table, 'Consumption', that links to the Countries table by the attribute 'Country'. Country links to 'full_name'. (Not my design!)

I want to update an attribute for every record in Consumption when 'Country' has no match with 'full_name'. So for example, if Country is blank, or has a value that isn't in the Countries table.

If this should occur, I want to be able to assign a specific 'full_name' within the Countries table. I've made a row specifically for this scenario. I've been trying to use an update query but I've had no results so far.

Countries
34 - NO - No Site ID - $79.99

Any help would be greatly appreciated!

Thanks,
Jason
Mar 4 '08 #1
4 1819
JKing
1,206 Expert 1GB
Hi Jason,

Here's some SQL that I think should satisfy your needs.

Expand|Select|Wrap|Line Numbers
  1. UPDATE consumption SET consumption.country = 'Site ID'
  2. WHERE NOT Exists (SELECT countries.full_name FROM countries WHERE countries.full_name = consumption.country);
  3.  
I think I got all the field names correct from your description, so you should be able to copy and paste without any problems.
Mar 4 '08 #2
NeoPa
32,556 Expert Mod 16PB
Another way, more typical of what Access might produce for you within the design window, would be :
Expand|Select|Wrap|Line Numbers
  1. UPDATE [Consumption] AS tC LEFT JOIN [Countries] AS tCs
  2.     ON tC.Country=tCs.Full_Name
  3. SET tC.Country='No Site ID'
  4. WHERE tCs.Full_Name Is Null
Mar 5 '08 #3
jkwok
32
Thanks guys, both responses are really helpful!
Mar 5 '08 #4
NeoPa
32,556 Expert Mod 16PB
No worries. It's good to help :)
Mar 5 '08 #5

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

Similar topics

3
by: Fred | last post by:
Hi out there, I have problems finding a way to warn a user that another user intends soon to update the same specific row. Let me explain. User 1 get to a JSP "update customer record" page....
3
by: Earl Teigrob | last post by:
I am considering writing a Class that Selects, Adds, Updates and Deletes Nodes in an XML File but do not what to reinvent the wheel. (See XML file below) That data format would emulate records...
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: Jeff Brown | last post by:
Does anyone else ever feel like just giving up!!!!! When i edit a record and then update the database i get an error, although i can add a new record completely. The error is : An unhandled...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
15
by: Scotty | last post by:
I like to have a good insert, update and delete code The code below sometimes workl ok sometimes doesnt work, what i am doing wrong?? Sub SaveAny() Dim command_builder As New...
7
by: lmnorms1 | last post by:
Hello, I am trying to update an access database record date field that matches a specific date. The code is not working. Anyone have any advice? Here is the code: Dim gConnString As String =...
9
by: mtgrizzly52 | last post by:
Hi all, I've looked for an answer for this in lots of books, online in several discussion groups and have not found the answer which I feel may be very simple. What I want to do is have a...
1
by: afromanam | last post by:
Hello, Good morning, I have a question, hope someone can help me. I have a table with say, 5 columns, each named A,B,C,D,E The table was imported from Excel, so picture please this:
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.