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

MVFs create duplicate value in Query, how to avoid ?

215 128KB
ok, After I used MVFs (Multivalue Fields) to query thing, I got alittle problem with it, It created duplicate value in query, can anyone spot out the problem and give some solution idea ?

the result should be 20 rows since I have only 20 bills in table2.
here my query SQL (this code generate 28 rows, duplicate 8 rows)
Expand|Select|Wrap|Line Numbers
  1. SELECT Table2.NameClient, Table2.ID
  2.    , Table2.Item, Table2.Vol
  3.    , Table2.[Bill-date], Table2.Price
  4.    , IIf([Table2].[Bill-date] 
  5.          Between [table3].[from] 
  6.             And [table3].[to]
  7.          ,[table3].[km]
  8.          ,0) 
  9.    AS KM
  10. FROM Table2 
  11.    LEFT JOIN Table3 
  12.       ON Table2.Item 
  13.       = Table3.IDbrand.Value;
  14.  
I try left, right, inner join, and even "select distinct" (decrease from 28 to 24 rows, duplicate 4 rows)

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT Table2.NameClient, Table2.ID
  2.    , Table2.Item, Table2.Vol
  3.    , Table2.[Bill-date], Table2.Price
  4.    , IIf([Table2].[Bill-date] 
  5.          Between [table3].[from] 
  6.             And [table3].[to]
  7.          ,[table3].[km]
  8.          ,0)
  9.       AS KM
  10. FROM Table2 
  11.    INNER JOIN Table3 
  12.       ON Table2.Item 
  13.       = Table3.IDbrand.Value;
it still have lot of duplicate rows.







Did anyone deal with this problem ? how to avoid duplicate rows created by MultiValue Field ?
Attached Images
File Type: jpg 1.jpg (70.8 KB, 263 views)
File Type: png 2.PNG (9.6 KB, 199 views)
File Type: jpg 3.jpg (85.9 KB, 333 views)
Oct 7 '15 #1
5 1147
hvsummer
215 128KB
oh god, I find out, not MVFs, but the "between .. and .." create these duplicate field.

ok, I have to compare bill-date which is between start day (from) and end day (to) in table to determine whether it have table3.KM or not.

first Access compare ID, if ID match in relationship, then I'll calculate iif condition, but why it give back duplicate result ?
this is not MFVs problem anymore, it's SQL's problem

help me plz, I still suck at SQL ==
Oct 7 '15 #2
zmbd
5,501 Expert Mod 4TB
this is not MFVs problem anymore, it's SQL's problem
Are you sure?
:)
(I'm teasing here :) )

Let's take a careful look at things...
---
Looking at the results in the third image, review the values returned in field [KM] for the indicated "duplicate" records. [KM]=0 for one record and [KM]=1000 for the second record.
> To me, this indicates that there is no duplication of the records.

If you do not already do so, try adding a primary key to all of your tables.
Expand|Select|Wrap|Line Numbers
  1. Table3:
  2. [PK][From_date][To_Date][IDBrand][KM]
Showing this Primary key in your results would help you (and us) to determine if the record is an actual duplicate or a related record to the search.
--
I've tried to re-create you database in my test environment.
Once again, I am not seeing duplicated records in that the value of [KM] is different. What I am seeing (with the help if the primary key) is that the same record from table2 is being returned for each matching value of the calculated field [KM] between the joins.

I am also getting slightly different values in the recordset for [KM].. most likely because I am working only with the sample data provided :)
For example the first duplicated set of records (note I have a primary key here. I initially designed the tables and queries without the primary key (breaking my own rules) and the results were the same for me either way...
Expand|Select|Wrap|Line Numbers
  1. From the first query:
  2. Table2.PK    Table2.NameClient    Table2.ID    Table2.Item    Table2.Vol    Table2.Bill_date    Table2.Price    KM
  3. 2    a    1    2    2    2015-01-01    5    1000
  4. 2    a    1    2    2    2015-01-01    5    2000
Expand|Select|Wrap|Line Numbers
  1. and the second query:
  2. Table2.PK    Table2.NameClient    Table2.ID    Table2.Item    Table2.Vol    Table2.Bill_date    Table2.Price    KM
  3. 2    a    1    2    2    2015-01-01    5    1000
  4. 2    a    1    2    2    2015-01-01    5    2000
((NOTE) I've not spaced the result out to match the column names here so that it is easier to see the returned values without scrolling the table :) )
--
Without your table relationships, there may be other things going on here that I don't readily see. I'll have to take a better look in little bit.

--
It would be helpful to have a few rows of the records you are expecting to have returned. If you use the [CODE/] button in the formatting toolbar, you can hand type these (as I have done above) as a formatted table.
One thing of note... do not use the [tab] key... use [spaces] to create your columns :)

--
It's my day off, and of course, the kids have no school today for some teacher training session... and the kids are trying to destroy the house ( :sigh: ) so I have to take a break for the moment.

IN the meantime, I've attached a zip-file of the test database I've created to work thru this with you so that our other experts will have something to play with. WE have some real SQL-Wizards!

--

Also:
You should avoid using reserved words and tokens as field names, file names, etc....

SQL Reserved Words - Office 2013 or later (read more)

This is from Allen Browne... his list has a little more detail
Problem names and reserved words in Access this list hasn't been updated since 2010; however, I've not found a word on it yet that wasn't a potential problem :)
Expand|Select|Wrap|Line Numbers
  1. [id] [Key_Tokem] [Reserved by]
  2. 1506 FROM JET reserved (kb248738);SQL Server reserved;ODBC (kb125948)
  3. 2253 TO JET reserved (kb248738);SQL Server reserved;ODBC (kb125948) 
  4.  
  5.  
>>> I you do not already do so, I highly, highly, advise having a primary key in all tables. I tend to you the autonumber field and I do not normally use the PK for anything other than a record id value. Normally, I do not use the PK as anything meaningful to the human user. I learned this the hard way when we changed how samples were identified. Fortunately, I had a fair understanding of SQL and VBA by then and the transition wasn't too horrible... but took a long time to code and implement on the legacy records.

Finally, Please note, the DB-Attachment is in Acc2013 format. In general, I have not had issues with ACC2010 opening these files; however, ACC2007 has occasionally choked and ACC2003 will not open this file.
Attached Files
File Type: zip 964349.zip (38.8 KB, 35 views)
Oct 23 '15 #3
hvsummer
215 128KB
oh my, old question that I have resovled and forgot to mention ==

Still thank you, zmbd, I have solution for this in my db already lol
since they're Many-to-Many relationship, I use group query to clear the duplicate.

not really a duplicate rows, I mean I want only 1 KM return from query, not 2 value like example due to compare between value. So I use sum() to calculate the total KM (since I set value return between range, and return 0 if not valid) so KM value will return right value.

I like this part: "and the kids are trying to destroy the house "

all database I ask you guy here is the simple model, so I just choose random shortest word to explain my idea, don't worry about reserve work, I know bout it and believe me, I will not suffer that problem since I use my language to name my field haha
Oct 23 '15 #4
zmbd
5,501 Expert Mod 4TB
Would you mind posting your SQL solution so that others that find your thread can benefit?

Thnx
Z


(house is still standing... I am however, soaked. )
Oct 23 '15 #5
hvsummer
215 128KB
I test it in "test.accdb" but actually after resolve, I've change code to solve next problem, so I'll try to recall it ==

Expand|Select|Wrap|Line Numbers
  1. SELECT Table2.NameClient, Table2.ID, Table2.Item, Table2.Vol, Table2.[Bill-date], Table2.Price,
  2. sum(IIf([Table2].[Bill-date] Between [table3].[from] And [table3].[to], [table3].[km],0)) AS KM
  3. FROM Table2 
  4.    LEFT JOIN Table3 
  5.       ON Table2.Item 
  6.       = Table3.IDbrand.Value
  7. Group by Table2.NameClient, Table2.ID, Table2.Item, Table2.Vol, Table2.[Bill-date], Table2.Price
  8. Order by Table2.NameClient, Table2.ID, Table2.Item;
  9.  
seem like that, since my problem is far more harder than this, I split my model into many pieces to solve.
this is only 1 pieces that I solved ==
Oct 24 '15 #6

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

Similar topics

2
by: Jason | last post by:
I have a table of 650,000 records associated to contracts. Some of the contracts have multiple records but each contract only has one Active Record (there might be several inactive records). ...
1
by: John M | last post by:
Hi, I have two incomplete lists of staff which combined create a full list of staff with duplicates. I wish to create a full list with no duplicates. Each member of staff has and obviously a...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
1
by: Sagaert Johan | last post by:
How to prevent the designer to create a value for a property in InitializeComponent ? I do not want the designer to create an initialisation entry in the InitializeComponent method. Is there...
5
by: lyne_asp | last post by:
Hello everbody, Please help me to remove the duplicate value. I have this code Do until objRSEmail.eof tgroup = objRSEmail("tEmailName")&"@city.com;"&tgroup ...
3
by: debasis6677077 | last post by:
I want to create a temporary query at runtime. I am using CreateQueryDef but compilation error comming. I have used the following coding Set database = CodeDb Dim dbsSunData As database ...
3
by: spl | last post by:
What is the fastest way to find a duplicate value in an array of 10 elements. I have to find just any one first occurrence of the duplication. Lets say I have ary={10, 20, 40, 90, 30, 60, 35, 40,...
1
by: krishanusasmal | last post by:
I am learning in PHP and HTMl. AND XAMPP. when i inserting any duplicate value. I want to display message with duplicate message or the data already exist or something like that. Plz. help me.
1
by: inder | last post by:
I have two fields Phone1 and Phone2 in my form. I want Phone1 after update to check its duplicate value in both phone1 and phone2. Similarly Phone2 to check phone2's duplicate value in both phone1...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.