Hello all. I've got the query:
SELECT DISTINCT tblCustomer.Customer_id, tblCustomer.Customer_firstName, tblCustomer.Customer_lastName, tblTicketType.TicketType_subscriber
FROM (tblCustomer INNER JOIN tblAttendance ON tblCustomer.Customer_id = tblAttendance.Customer_id) LEFT JOIN tblTicketType ON tblAttendance.TicketType_id = tblTicketType.TicketType_id
WHERE (((tblTicketType.TicketType_subscriber)=True) AND ((Year([tblAttendance].[Attendance_date]))=2006));
and it's not working properly.
It gets the correct values fine, but I have problems where a single record in tblCustomer corresponds to two seperate records in tblTicketType that has the first record of TicketType_subscriber set to 'True' and the second to 'False'. This results in bringing up the same customer ID, etc twice in my report.
The only way that I know that I can get around this (in MySQL anyway) is to use a GROUP BY statement, that'd make it look like
SELECT DISTINCT tblCustomer.Customer_id, tblCustomer.Customer_firstName, tblCustomer.Customer_lastName, tblTicketType.TicketType_subscriber
FROM (tblCustomer INNER JOIN tblAttendance ON tblCustomer.Customer_id = tblAttendance.Customer_id) LEFT JOIN tblTicketType ON tblAttendance.TicketType_id = tblTicketType.TicketType_id
WHERE (((tblTicketType.TicketType_subscriber)=True) AND ((Year([tblAttendance].[Attendance_date]))=2006)) GROUP BY tblCustomer.Customer_id;
Unfortunately, Access won't allow a GROUP BY clause like this without every field that I'm selecting being included, and that means that because there's two distinct values for TicketType_subscriber that the record still comes up twice.
Hello. I'm making a database to store movie info for a DVD collection. I have a table with fields: title, year, runtime and such. I want an indefinite number of genre to be associated with a movie, so I created a "genre" table and a junction table between that and the "movie" table. Now, on form I want to be able to filter a list of movies based on a genre selection from a combo box. The only way I can see to do this is to make the rowsource of the listbox a query with "tblMovie.MovieID, tblMovie.Title, tblJunction.GenreID" connected through MovieID. This would work except that if a movie is associated with more than one genre on the junction table, the movie appears on the list more than once. I want a movie to appear only once. That's my problem. Thanks in advance for the help.
I am trying to calculate annual percentiles of a large set of data and I have only been successful at retrieving the percentile of the entire data set (and not by the grouping). See provided example database for code/query. Query1 is what I want to happen to make the Percentiles table.
I have this table ("people") and an example of possible rows:
id(key) COL 1 COL2 department country name 1 xx yy KPP USA John 2 zz kk KPP USA John 3 ss ff TLL USA John 4 ww qq PPO Italy Marco 5 jj uu PPO Italy Marco
I have to count the number of distinct DEPARTMENT for each NAME; so, for John should be 2 (KPP and TLL) and for Marco 1 (PPO).
I have tryed in this way:
SELECT COUNT(DISTINCT department) AS NumberOfDifferentDepartments FROM people GROUP BY name;
Hi, Wish if some one could help me ASAP. I have a table which contains name, tel, email i need to import only records which have distinct email. I do need need to import data of all three fields but only which has distinct email. As there are number of record which are duplicate. They have different names but same email. So i need to condition only for distinct email but dump the data in a new table with all three records. so same names can have different email. but same email can't have duplicate email. So need only records which have distinct email. Please help .......
Is there a way to have an expression in the control source of a text box in a report, that re-starts or is exclusive for every group within the report?
I stumbled upon the Option Group function just yesterday and, happy as a clam, I created a group with 2 options in radio button style. I assigned the values to a field called Registration_Type as the 2 options are "Confirmed Registrants" and "Prospective Attendees".
[Great. That part works well. When I look at the table, a 1 or a 2 is in that field so it's great to know how to control accidental ticking of radio buttons (previous 450 records or so didn't have this option group functionality so one might easily tick one of the buttons. So one part of controlling option group I know I can handle via the table itself for now.]
The challenge is how to ensure the user always ticks one or the other ... I went back to the main table and tested the 'required entry' option for the Registration_Type field but forcing an action like this is not ideal in my mind. The usual error message vagueness for the average user is no good and I don't want to limit the user so much.
Is there a way to simply have a popup come up warning that neither radio button was ticked? Perhaps something linked to the form - i.e., maybe "after update"?? I only learned about attaching code to before and after update on controls a couple of days ago, so not sure if this would be best approach.
Just something to let the user know that nothing has been ticked in the option group as that controls in which of 2 reports the data will show up in so any record not ticked might mean a registrant being left out, which would be rather disastrous <g>.
I have a query with in excess of 20 fields. One of the fields is [POLICY NUMBER]. I want to use DISTINCT to only show rows of data where the Policy number is unique.
If I put DISTINCT after SELECT the query will only include results where the combination of values from all the fields are unique and I dont want this.
I am running a query in a combo box but for some reason the following SQL statement does not give me the result I am after. Which is to only displaying the distinct records. It continues to display the multiple occurrences of the records. I also tried distinctrow with no better results.....
and i needed a return (WHERE clause) when job_id is the same (i.e 2), and the crew_id is repeated like 4,4 and 33, how would i write it. I am trying to only sum the rows when this condition is fulfilled. Can anyoen help me
Could anyone explain me the following sysntax : ... where ((cond1 and cond2) and (fld1<>'54')<>'60') the syntax did not return any error while executing the query.
I have an select statment that pulls data from a server. This server is really slow, and there is quite a bit of data. This statement has the following where clause.
"WHERE upc_number = '" & strPikWhere & "' AND ((dbo_root_description_type.description_name)='PFM S' Or " & _
"(dbo_root_description_type.description_name)='Full tech') AND ((dbo_root_price.zone) Not Like '8*') " & _
I was wondering if the order of these where statements would make a difference, and if so how?
I have a query using the between clause with dates #01/01/2006# and #01/01/2007#. I have been reading a little on the between clause and it differs from SQL program to SQL program. What are its characteristics in MS Access is it >=#01/01/2006# AND <=#01/01/2007# or >=#01/01/2006# AND <#01/01/2007#.
When I do a Debug Print for where I get cardnumber = 1111111 The card number is a string because it might have a letter in it don't i need it to be cardnumber = "1111111"
I have a table "addresses" that has the following fields....... id - type - street1 - street2
and type can be one of the follwoing graduation,home,work
I am trying to write a query that gives the graduation address if it exists or if graduation doesnt exist it gives the home address..... I was thinking of an If clause but do not know how to do it.... can i write a module...??? Any help on this is appreciated..... Any other method also can be suggested....
I have a table with the follwing; ShopID, CustomerID, Month, Item_ref, Product Category
There are about one thousand shops. The CustomerID field is only unique per shop. I.e. all transactions for customer ID '002' in shop 1 will be for the same customer, but customer ID '002' could appear in another shop and will be a different customer, I want to be able to bring back a list of distinct customers, the number of items they have had and the product categories.
Has anyone got any ideas how I do this? I presume I would need to do a count distinct or something??
Hello, I have a strange problem: one of my comboboxe is looking up a column in one of my table. Some of the record can be duplicated so I decided to change SELECT to SELECT DISTINCT in my SQL for the row source but it doesn't seem to change anything. Is anybody's got an idea why?
I want to get disctinct count of InvoiceNo while summing up Amount by Date and CustomerID in one query. Firstly, I tried to use correlated query to count unique records but it failed. SELECT A.Date, A.CustomerID, (SELECT COUNT(B.InvoiceNo) FROM Table1 B WHERE B.Date = A.Date AND B.CustomerID = A.CustomerID ) AS CountOfDistInvNo, Sum(A.Amount) AS SumOfAmount FROM Table1 A GROUP BY A.Date, A.CustomerID;
The result of Count is not a unique count. Can anyone tell me what's wrong with this correlated query? :confused:
After hours of googling on internet, the solution I got is equivalent to querying on top of the resulting table from another query.
My final query is
SELECT B.Date, B.CustomerID, Count(B.InvoiceNo) AS CountOfInvoiceNo, Sum(B.SumOfAmount) AS SumOfAmount FROM (SELECT A.Date, A.CustomerID, A.InvoiceNo, SUM(A.Amount) AS SumOfAmount FROM Table1 A GROUP BY A.Date, A.CustomerID, A.InvoiceNo) AS B GROUP BY B.Date, B.CustomerID;
Is there a better solution than this in Access? :)
Tried several suggestions in the forum but haven't found one to match my needs.
I have one table, Jupiter and need to use this query
SELECT Jupiter.codename AS Build, Count(Jupiter.tooling_ind) AS [# Needing Tool], Count(IIf([tool_req_type]='OR',([requisition_no]))) AS [# Tooled], [# Tooled]/[# Needing Tool] AS [% Tooled], Jupiter.tooling_ind FROM Jupiter GROUP BY Jupiter.codename, Jupiter.tooling_ind HAVING (((Jupiter.tooling_ind)="Y"));
For each "codename", there is an attached "part_no" which can appear under a codename several times. The problem is that I need to count only one instance of the "part_no" for each "codename". So, my query looks like this: Build # Needing Tool #Tooled LP1 769 192
The # Needing Tool is counting every record that, say pn 10592 shows up in and I need it to be counted only once in each "Build"
I did try this suggestion I found with no results.
SELECT Jupiter.codename AS Build, Count(Jupiter.tooling_ind) AS [# Needing Tool], Count(IIf([tool_req_type]='OR',([requisition_no]))) AS [# Tooled], [# Tooled]/[# Needing Tool] AS [% Tooled], Jupiter.tooling_ind FROM (SELECT DISTINCT Jupiter.part_no FROM Jupiter)Jupiter GROUP BY Jupiter.codename, Jupiter.tooling_ind HAVING (((Jupiter.tooling_ind)="Y"));
I have a problem using distinct or distinctrow in one of my query. The result shown reflects all records instead of distinct records. May I know what may be the cause of the problem?
Query: SELECT DISTINCT Assets.*, Depreciation.DepreciationDate, Depreciation.DepreciationAmount FROM Assets LEFT JOIN Depreciation ON Assets.AssetID=Depreciation.AssetID;