473,406 Members | 2,705 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,406 software developers and data experts.

combining duplicate data onto a single record

I have a table of data that has duplicate values in the pagenumber
field.
How can I combine the data so that the page numbers of duplicate part
numbers are on one record for that part number?
Here is what "table1" looks like now. Note that partnumbers 10-20 and
20-62 duplicate data, except for the pagenumbers, which are different.

partnumber price pagenumber
10-20 25.00 B5
10-20 25.00 C2
14-30 20.00 H2
20-62 35.20 B22
20-62 35.20 D5
49-63 1.23 A22
50-32 58.56 B19
Below is the way i want the table to look after the data are
recombined.

partnumber price pagenumber partnumber2
10-20 25.00 B5 C2
10-30 20.00 H2
20-62 35.20 B22 D5
49-63 1.23 A22
50-32 58.56 B19

How can I do this?

Thanks,
Craig

Nov 13 '05 #1
3 5617
There may people out there who are smarter than I am and who have a
better answer, but here is one for you.
You only showed a max of 2 page numbers, but I am guessing that you may
have more. If you only have two, this could be done this way.
SELECT aPage1.partnumber,MaxPrice,pagenumber1,pagenumber2
FROM
(SELECT partnumber, Max(price) AS MaxPrice, Min(pagenumber) AS
pagenumber1
FROM Table1
GROUP BY partnumber) as aPage1 LEFT JOIN
(SELECT partnumber, Max(pagenumber) AS pagenumber2 FROM Table1
GROUP BY partnumber
HAVING count(pagenumber)>1) as aPage2 ON
aPage1.partnumber=aPage2.partnumber

If you need it to be dynamic (so that you can have x number of pages),
you'll need to buld a table so that access can build it's execution
plan for the crosstab. These are pretty easy and can be done without
the user ever knowing - using vb.

First Build a table:
SELECT Table1.partnumber, Table1.price, Table1.pagenumber, "PageNumber"
& (select count(pagenumber) from table1 as t WHERE
t.partnumber=table1.partnumber AND t.pagenumber<=table1.pagenumber) AS
PageCount INTO PageCount
FROM Table1;

Then run your crosstab query on the built table:
TRANSFORM Max(PageCount.pagenumber) AS MaxOfpagenumber
SELECT PageCount.partnumber, Max(PageCount.price) AS MaxPrice
FROM PageCount
GROUP BY PageCount.partnumber
PIVOT PageCount.PageCount;

Hope that's not too confusing
Pachydermitis

Nov 13 '05 #2
Well, that worked perfectly for the first table.
Thank you very much for your help.

Now, I have another table that has similar data, but an extra column.

This other table has a 4th column, "disc" . This is a discount code.
How do I run the queries you created perviously and list the "disc"
value once, not twice

For example, using the pervious data, here is the current table with
duplicates.

partnumber price pagenumber disc
10-20 25.00 B5 C
10-20 25.00 C2 C
14-30 20.00 H2 F
20-62 35.20 B22 G
20-62 35.20 D5 G
49-63 1.23 A22 C
50-32 58.56 B19 F

The new table would look like this...

partnumber price pagenumber partnumber2 disc
10-20 25.00 B5 C2 C
10-30 20.00 H2
F
20-62 35.20 B22 D5 G
49-63 1.23 A22
C
50-32 58.56 B19
F

I tried to modify the previous queries, but nothing worked.

Thanks again for you help on this.
Craig.

Nov 13 '05 #3
Craig,
I'm assuming you want the disc that corresponds to pagenumber1. If so
Just add table1 back in again and link the two.
The reason it didn't work is probably because access changes the '(' on
the derived tables or sub queries to a '['. It's retarded because as
long as you only view it in design view you are fine, but the moment
you go into sql view the query won't work until you change them back.

SELECT aPage1.partnumber, aPage1.MaxPrice, aPage1.pagenumber1,
aPage2.pagenumber2, table1.disc
FROM ((SELECT partnumber, Max(price) AS MaxPrice, Min(pagenumber) AS
pagenumber1 FROM Table1 GROUP BY partnumber) AS aPage1 LEFT JOIN
(SELECT partnumber, Max(pagenumber) AS pagenumber2 FROM Table1 GROUP
BY partnumber HAVING count(pagenumber)>1) AS aPage2 ON
aPage1.partnumber = aPage2.partnumber) INNER JOIN table1 ON
aPage1.pagenumber1 = table1.pagenumber;

Good Luck
Pachydermitis

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
4
by: Tony Williams | last post by:
I want to combine two tables into one. I have a table with all the field definitions from two other tables. I now need to update this new table with the data from the other two tables.However both...
0
by: Mark C via AccessMonster.com | last post by:
Ok bare with me on this one.... I have 1 table "Expenses" that holds about 50 fields broken down into sub categories. I have a Subform tied to a main form so that when I pull up a client it...
2
by: Rob Richardson | last post by:
Greetings! I am struggling to understand data binding in VB.Net, and it's slow going. I have a list box bound to a dataset that is filled from a SQL Server table. In addition to the list...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
1
by: NumberCruncher | last post by:
Hi All, I am struggling with setting up my first system of tables, forms,and reports, and could use your help! I am setting up a database to keep track of the production of a produced item. The...
5
by: KewlToyZ | last post by:
Good day, I am stuck in a strange situation. SQL 2000 Server, creating a stored procedure to use in Crystal Reports 11. I am trying to build a report without creating a table or temprorary table in...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
4
by: Thomas Arthur Seidel | last post by:
Hello to all, I have a small or big problem with a customer data base, where during a change of system we might have created duplicate records. This should be easy to find, you might think, but,...
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: 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?
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
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,...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.