Adding a Field to an existing table to add a new value

PaulCL

New Member
Joined
Jul 9, 2014
Messages
43
Hello,
How do I go about adding a field, to an existing table, that I can use to designate the highest value among a set of duplicate id's in a different field.
Thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
If it is a native Access table, you go to Design View of the table, you can add new fields.

However, the general rule of thumb is that you should never store a value in a table which can be calculated in a query. It ruins the dynamic nature of the database and violates the rules of normalization.
There usually isn't a reason to, as you can use a Query for just about anything that you can use a Table for.
 
Last edited:
Upvote 0
If it is a native Access table, you go to Design View of the table, you can add new fields.

However, the general rule of thumb is that you should never store a value in a table which can be calculated in a query. It ruins the dynamic nature of the database and violates the rules of normalization.
There usually isn't a reason to, as you can use a Query for just about anything that you can use a Table for.[/]

ThanksJoe,

What would the query look like if my table looks like this. I want to add the text "HQ" for any duplicate ID's i.e.
Firm ID Volume Added Field

AK 1,000
AL 10,000
AL 19,000 HQ
AL 8,000
AR 5,000
AZ 20,000
CA 50,000 HQ
CA 45,000
 
Upvote 0
OK. I would do this in a series of two queries. The first, which returns all duplicate Firm IDs, and their maximum.
If your table was named "Table1", it would be an Aggregate Query that looks like this:
Code:
SELECT Table1.[Firm ID], Count(Table1.[Firm ID]) AS [CountOfFirm ID], Max(Table1.Volume) AS MaxOfVolume
FROM Table1
GROUP BY Table1.[Firm ID]
HAVING (((Count(Table1.[Firm ID]))>1));
Let's name this query MaxVolume.

Now, link this query back to your original table in a new query, and you can get what you want like this:
Code:
SELECT Table1.[Firm ID], Table1.Volume, IIf(Nz([CountOfFirm Id],0)<>0,"HQ","") AS [Added Field]
FROM Table1 LEFT JOIN MaxVolume ON (Table1.Volume = MaxVolume.MaxOfVolume) AND (Table1.[Firm ID] = MaxVolume.[Firm ID]);
 
Upvote 0
OK. I would do this in a series of two queries. The first, which returns all duplicate Firm IDs, and their maximum.
If your table was named "Table1", it would be an Aggregate Query that looks like this:
Code:
SELECT Table1.[Firm ID], Count(Table1.[Firm ID]) AS [CountOfFirm ID], Max(Table1.Volume) AS MaxOfVolume
FROM Table1
GROUP BY Table1.[Firm ID]
HAVING (((Count(Table1.[Firm ID]))>1));
Let's name this query MaxVolume.

Now, link this query back to your original table in a new query, and you can get what you want like this:
Code:
SELECT Table1.[Firm ID], Table1.Volume, IIf(Nz([CountOfFirm Id],0)<>0,"HQ","") AS [Added Field]
FROM Table1 LEFT JOIN MaxVolume ON (Table1.Volume = MaxVolume.MaxOfVolume) AND (Table1.[Firm ID] = MaxVolume.[Firm ID]);
Thanks, I will give it a try.
 
Upvote 0
What would the queries look like as excel query in a spreadsheet with the same data? Thanks
 
Upvote 0
I don't know. I don't do database queries in Excel. I do all mine in Access.
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top