Duplicated records (1 Viewer)

kafka89

New member
Local time
Today, 20:10
Joined
Sep 16, 2018
Messages
1
I`m having an issue with my MS Access query and I hope you can help me. I want product "ABC" to have code "6029" if the parent is anything else than "GYF", "RGY" & "DRF".

The mapping looks as follows:

| Output_code | Account | Product | Parent |
+-------------+---------+----------+--------+
| 6029 | income | ABC | |
| 7029 | income | ABC | GYF |
| 7029 | income | ABC | RGY |
| 7029 | income | ABC | DRF |
+-------------+---------+----------+--------+
End result would be:

+-------------+---------+----------+--------+
| 6029 | income | ABC | DTF |
| 6029 | income | ABC | DHS |
| 7029 | income | ABC | GYF |
| 7029 | income | ABC | RGY |
| 7029 | income | ABC | DRF |
+-------------+---------+----------+-------
How it works right now:

+-------------+---------+----------+--------+
| 6029 | income | ABC | DTF |
| 6029 | income | ABC | DHS |
| 7029 | income | ABC | GYF |
| 7029 | income | ABC | RGY |
| 7029 | income | ABC | DRF |
| 6029 | income | ABC | GYF |
| 6029 | income | ABC | RGY |
| 6029 | income | ABC | DRF |
+-------------+---------+----------+--------+

Code:
  Select A.*, B.Output_Code, "Product" as Comment from Source as A
  inner join Mapping as B on (B.Account=A.Account and B.Product = A.Product) 
  where (B.Parent = "" or B.Parent <> A.Parent);  
  union all  
  Select A.*, B.Output_Code, "Product+Parent" as Comment from Source as A 
  inner join Mapping as B on (B.Account=A.Account  and B.Product = A.Product 
  and A.Parent = B.Parent) where B.Parent <> "";


First part (Product) is not working as expected and combinations like ABC+RGY appear twice with both "6029" and "7029".

I tried using select within select (for this I introduced rowid) and it worked but right now is takes 30 min for my query to process (instead of 5 min).

Code:
Select A.*, B.Output_Code, "Product" as Comment from Source as A inner join 
Mapping as B on (B.Account=A.Account and B.Product = A.Product)
where (B.Parent = "" or B.Parent <> A.Parent) [B]and A.rowid not in (Select 
A.rowid from Source as A inner join Mapping as B on (B.Account=A.Account and 
B.Product = A.Product and A.Parent = B.Parent) where B.Parent <> "")[/B];

Could you kindly share your ideas on what is the proper way of building the first query so it doesn`t affect the performance so heavily?
 

Ranman256

Well-known member
Local time
Today, 14:10
Joined
Apr 9, 2015
Messages
4,339
your 3rd table has no duplicates.
it has the correct product.
 

isladogs

MVP / VIP
Local time
Today, 19:10
Joined
Jan 14, 2017
Messages
18,209
I'm unclear how 4 records in the first list become 5 in the second.

Using a UNION query will give you additional unwanted results as in the final list

If you want to change the Output code in the original table, use a UPDATE query instead.
OR if you just want these to be displayed differently without changing the table, use a query with the REPLACE function to replace 7029 with 6029 for your specific criteria
 

Users who are viewing this thread

Top Bottom