Hello All.
I am trying to run a query, but am coming across an anomaly. Before I begin, I would like to ask one thing. I understand that my database may not be designed the best. And I sincerely do appreciate the advice. However, I am not here to make my database fit the proper standardized parameters. I, frankly, am not allowed to do this. Therefore, I am trying to get around issues by creating complicated queries. So while the advice on how the database should be is appreciated, please do not tell me that my database design is flawed.
Moving on.. First of all, let me explain my tables.
I have two tables in my query. (These are not the actual names fyi). tblMain & tblEvent.
tblMain consists of the fields: “EventNum”, “Date”, and “AdditionalNum”. The primary key is “EventNum”
TblEvent consists of the fields: “EventNum”, “EventType”, “City1”, “City2”, “City3”. The primary key is a compound key comprising of EventNum and EventType.
Please see an example of a form I use below. The pictures are of the same EventNum, but two separate records.
<see attachment in the zipped folder>
I want to run a query that will, in effect, totally ignore the “Record 2 of 2”. In order to do this I use the following aggregate functions in my query:
<please see other zipped folder for pic of my query>
I then enter criteria into the “Date” and “City” columns. Note, I only search for one “City” at a time.
I use the MIN Function because “Alpha” also supersedes “Beta.” Therefore in my query, I will have “Alpha” returned, and not “Beta” as “Alpha” comes fist alphabetically.
I use the FIRST function for City 1, 2, and 3 because I only want what ever city that appears first in my records to be counted. For example, lets look at the two pictures above. I want my query to return the following:
City1 = New York
City 2 = London
City 3 = Null
Say for example I am searching for Beijing using the query above. I DO NOT want my query to show me Event Num “12” because Beijing is NOT the First City2 that is mentioned.
Likewise, if I search for Madrid, I DO NOT want to see Event Num “12” because the First City3 mentioned IS “null.”
My problem is strange. Sometimes it happens, sometimes it doesn’t.
Basically, my query appears to override the fact that I only care about City1, 2, or 3 AS LONG AS it is the FIRST identified city.
Additionally, my query appears to be ignoring the fact that City3 is null. It just goes straight to Madrid.
I am trying to run a query, but am coming across an anomaly. Before I begin, I would like to ask one thing. I understand that my database may not be designed the best. And I sincerely do appreciate the advice. However, I am not here to make my database fit the proper standardized parameters. I, frankly, am not allowed to do this. Therefore, I am trying to get around issues by creating complicated queries. So while the advice on how the database should be is appreciated, please do not tell me that my database design is flawed.
Moving on.. First of all, let me explain my tables.
I have two tables in my query. (These are not the actual names fyi). tblMain & tblEvent.
tblMain consists of the fields: “EventNum”, “Date”, and “AdditionalNum”. The primary key is “EventNum”
TblEvent consists of the fields: “EventNum”, “EventType”, “City1”, “City2”, “City3”. The primary key is a compound key comprising of EventNum and EventType.
Please see an example of a form I use below. The pictures are of the same EventNum, but two separate records.
<see attachment in the zipped folder>
I want to run a query that will, in effect, totally ignore the “Record 2 of 2”. In order to do this I use the following aggregate functions in my query:
<please see other zipped folder for pic of my query>
I then enter criteria into the “Date” and “City” columns. Note, I only search for one “City” at a time.
I use the MIN Function because “Alpha” also supersedes “Beta.” Therefore in my query, I will have “Alpha” returned, and not “Beta” as “Alpha” comes fist alphabetically.
I use the FIRST function for City 1, 2, and 3 because I only want what ever city that appears first in my records to be counted. For example, lets look at the two pictures above. I want my query to return the following:
City1 = New York
City 2 = London
City 3 = Null
Say for example I am searching for Beijing using the query above. I DO NOT want my query to show me Event Num “12” because Beijing is NOT the First City2 that is mentioned.
Likewise, if I search for Madrid, I DO NOT want to see Event Num “12” because the First City3 mentioned IS “null.”
My problem is strange. Sometimes it happens, sometimes it doesn’t.
Basically, my query appears to override the fact that I only care about City1, 2, or 3 AS LONG AS it is the FIRST identified city.
Additionally, my query appears to be ignoring the fact that City3 is null. It just goes straight to Madrid.