473,513 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining columns from 3 tables and removing duplicates by date

1 New Member
I have 3 tables with the following relevant fields:

ItemsFrmManufacturer
Date......SerialNum.....Description.....Status
01012010..000001..... Item1..... IN
01022010..000002..... Item1..... IN

ItemsShipped
Date......SerialNum.....Description.....Status
06012010..000001..... Item1..... OUT
06012010..000003..... Item2..... OUT
07152010..000001..... Item1..... OUT

ItemsFromCustomerRepair
Date......SerialNum.....Description.....Status
05012010..00004..... Item3..... IN
06302010..00001..... Item1..... IN

I need to make a query or table takes the data from teh three tables and combines them into one table with the most recent record for each serial number.

CurrentStatus
Date......SerialNum.....Description.....Status
07152010..000001..... Item1..... OUT
01022010..000002..... Item1..... IN
06012010..000003..... Item2..... OUT
05012010..000004..... Item3..... IN

Any help with a sql statement to do this would be greatly appreciated.
Aug 16 '10 #1
1 1056
NeoPa
32,557 Recognized Expert Moderator MVP
Hi. Welcome to Bytes!

I'm sorry to say that I think your data structure is all wrong (See Normalisation and Table structures). You should have a single table with an extra field which indicates which situation they reflect. That way, none of this is a problem. The data is already there just as you need it.

This is not simply about this problem either. I can guarantee you that you will encounter further troublesome issues if you continue with your current design. Don't say you haven't been warned.

That all said. Your design is fundamentally your concern, and the specific answer to your question would be :
Expand|Select|Wrap|Line Numbers
  1. SELECT 'Manufacturer' AS Source
  2.      , *
  3. FROM   [ItemsFrmManufacturer]
  4.  
  5. UNION ALL
  6. SELECT 'Shipped' AS Source
  7.      , *
  8. FROM   [ItemsShipped]
  9.  
  10. UNION ALL
  11. SELECT 'Repair' AS Source
  12.      , *
  13. FROM   [ItemsFromCustomerRepair]
Aug 16 '10 #2

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

Similar topics

5
6041
by: JackT | last post by:
Hi, I have the following SQL SELECT Table1.Col1, Table3.Col1 AS Expr1, COUNT(Table1.Col2) AS Col2_No, COUNT(Table1.Col3) AS Col3_No etc, FROM Table3 INNER JOIN Table2 ON...
4
3604
by: Drew | last post by:
I have a permission tracking app that I am working on, and I have made the insert page for it. I am having issues on how to prevent duplicates from getting entered. Currently the interface for...
4
11521
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...
16
4157
by: tyrfboard | last post by:
I've been searching for awhile now on how to remove duplicates from a table within an Access db and have found plenty of articles on finding or deleting duplicates. All I want to do is remove them...
6
5390
by: Don | last post by:
I'm thinking this is simple and I'm just not understanding how to do it but I have to ask because I'm stumped. I have a query (which is used to create a report) and three of the columns in this...
5
32318
by: asgars | last post by:
i have two tables, tab1 having N1 col and tab2 N2 col. now N1 is subset of N2. I need the information from tab2 (having N2) of all rows having the matching entry in N1 in tab1. For this i am...
2
2672
by: sjlung | last post by:
I apologise if this is a trivial question but I have appended three tables in access and within this table, there are duplicate entries. I have tried to set my reference number for this table to be...
7
3032
by: Frank | last post by:
Hi there, I'm trying to generate a report for an old database and I'm having trouble coming up with an elegant way of going about it. Using cursors and other 'ugly' tools I could get the job done...
7
3352
by: vsgdp | last post by:
I have a container of pointers. It is possible for two pointers to point to the same element. I want to remove duplicates. I am open to which container is best for this. I thought of using...
2
3849
by: Don Barton | last post by:
I have 2 tables, Table 1 has Name, NameID, and A, B, C fields. Table 2 has Name, NameID, and D, E fields. Several of the Names/NameID are the same in both databases. I want my merged the tables...
0
7157
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
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
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
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5084
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...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.