Need Help With DISTINCT Query

Apr 16, 2007

Hey all

Hope everyone is well.

Im having some probs with a DISTINCT query and hope you can help me out.

In the simplest terms I have a table that has 3 fields. Firstly the BikeManufacturer, then the BikeModel and finally the EngineCC.

Now from this table I am dynamically creating a drop down list via an AJAX request.

See it here .

When the user clicks on a manufacturer the select should be created showing DISTINCT BikeModel.

This could simply be achieved with a DISTINCT Statement but what I also want to do is order the list by the EngineCC.

Now if i put both fields into the DISTINCT statement i get duplications of the models since they dont all have the same EngineCC. But if i leave out the EngineCC from the select then I cant order by it.

Any ideas?

Thanks

View Replies


ADVERTISEMENT

Need Distinct Records Of Whle Table But Distinct On One Field

Sep 15, 2006

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 .......

View 1 Replies View Related

Distinct Rows From Non-distinct Data?

Oct 10, 2005

I have data which consists of:

xxxxx123 A.Nother 123456
xxxxx123 B.Jones 123457
xxxxx456 D.Smith 123458
xxxxx456 Z.Zephir 123489

How would I ensure that the query returned only unique rows (where column 1 is unique) based on the first alphabetical record of column 2?

Any ideas?

View 1 Replies View Related

Distinct Query

Feb 15, 2008

Hey all

I have data in the table.
(various IDs - in example below just 1)
Each ID has date and status.

I need to pull each ID only ones
for MAX date

If there are 2 like that (with different statuses) i need the one with lowest importance. Any advise ?


StatusLogIDDateID DateImportance
ssss02/04/200802/04/2008ghj6
ssss02/04/200802/04/2008ghj6
tttt02/04/200802/04/2008ghj5
tttt02/04/200802/04/2008ghj5
rrrrrr02/07/200802/07/2008ghj4
rrrrrr02/07/200802/07/2008ghj4
ssss02/08/200802/08/2008ghj6
ssss02/08/200802/08/2008ghj6
ssss02/11/200802/11/2008ghj6
ssss02/11/200802/11/2008ghj6
tttt02/11/200802/11/2008ghj5
tttt02/11/200802/11/2008ghj5

View 3 Replies View Related

Select Distinct In A Query

Oct 2, 2007

I am working in Access 2003. I have a combo box based on the query below that works perfectly except that it shows duplicate Department Names in the combo box. I have not been able to find any way to show the Department Name only once. I have tried putting in SELECT DISTINCT in the string, but to no avail I recieve an error :
ORDER By clause(DepartmentMembers.[DepartmentMembers]) conflicts with DISTINCT.

Any light you can shed on this subject would be greatly appriciated. I have been researching forums for over two days and have not been able to generate a solution to this. Thank you in advance!

SELECT Departments.[Department Name], DATA.[BUILDING LOCATIONS], DATA.[REPORTS TO], DATA.[DIRECTOR NAME], DATA.[NUMBER OF PERSONNEL], DATA.[PC NAMING CONVENTION], DATA.[CISCO SWITCH(ES) ATTACHED], DATA.[SERVER-BASED APPLICATIONS USED], DATA.[DEPARTMENT SHARE (Z:DRIVE)], DATA.[EXTERNAL SERVERS], DATA.[Department ID]
FROM (DATA INNER JOIN DepartmentMembers ON DATA.[Department ID]=DepartmentMembers.[Department ID]) INNER JOIN Departments ON (Departments.[Department ID]=DepartmentMembers.[Department ID]) AND (DATA.[Department ID]=Departments.[Department ID])
ORDER BY Departments.[Department Name], DepartmentMembers.[Department Members];

View 14 Replies View Related

DISTINCT And WHERE Arguments In SQL ASP Query

Jan 20, 2007

I'm going nuts here...can you privide some help.

I'm trying to QUERY an ACCESS database called ARQUIVO and i would like to have from the column EMPRESAS all the DISTINCT records that have the same 'aviacao' in the INDUSTRIA column.

and it goes like this:
Code:<%Set rse = Server.CreateObject("ADODB.Recordset")sSQL = "SELECT DISTINCT empresa FROM arquivo WHERE industria='Aviacao'" rse.open sSQL,con, adOpenStatic, adLockPessimistic, adCmdText%>

But all I get in a 500 error.

The fact is that if I use "*" instead of "empresa" the query runs but i list all the records with 'aviacao' in INDUSTRIA


I have this SQL query made in ACCESS - that does what I want - but it doesn't rune in mine ASP page.

SELECT DISTINCT arquivo.EMPRESA, arquivo.INDUSTRIA
FROM arquivo
WHERE (((arquivo.INDUSTRIA)="Cāmaras Municipais"));

Would anyone help on this?

View 1 Replies View Related

Distinct Count In A Query?

Sep 13, 2011

I have a query I have 4 fields:

E.G.

Field1 Field2 Field3 Field4
C 20 25 145541
C 40 20 145541
C 10 10 145540

D 20 20 145540
D 10 10 145538

I need to obtain:

C 70 55 2
D 30 30 2

I need to group Field1 and sum Field 3 and field3 and count the UNIQUE ID in field 4.

View 5 Replies View Related

Ordering A DISTINCT Query Of Dates?

Jul 20, 2005

Is this possible, if using the following:

SELECT DISTINCT (Format([Month],"mmm yyyy")) FROM Table;

Adding a ORDER BY [Month]; gives a "distinct and order by" conflict...

Is there any way to alleviate this?

I want to display a "mmm yyyy" formatted combobox in order (i.e. Jan 2005, Feb 2005, Mar 2005, etc...)

TIA!

View 7 Replies View Related

Query Help (distinct Conflicts With Order By)

Oct 26, 2004

Seems easy but I can't get it to work

Table Services
Pk_Service
Service_Name
MyDate
Fk_License

Table Licenses
Pk_License
License_Name

I need to get all the services for one license, but only once, you'll see what I mean

Pk Service Service_Name MyDate Fk_Licence
1 Base 10/5/2004 5
2 Base 12/6/2004 5
3 Super Base 11/4/2004 5
4 Base 20/10/2004 5
5 Super Base 17/7/2004 5

there's about 7000 records with the same 4 services recurring all the time

All I want for one license is the all distinct services for a chosen date

If I select License 5, and today's date, 26/10/2004, I would need the latest service (closest date but has to be inferior or equal), in this case

Pk Service Service_Name MyDate Fk_Licence
4 Base 20/10/2004 5
5 Super Base 17/7/2004 5

Here's the query I have:

select distinct Service_Name from Services where Fk_License=5 where MyDate <= SelectDate order by DateDiff('d',SelectDate,MyDate) DESC

where Fk_License is to get only the services for a particular license
distinct if to only get each service once
MyDate <= SelectDate if to get only the services older than the selected date
order by is to get the latest service cause there will be a lot of services older than the selected date

they say distinct conflicts with order by

Anyone knows how to do this query right?

View 6 Replies View Related

Limited List Rows In Distinct Row Query

Nov 21, 2006

Hello,
On a form I have a way to search for a record by using a listbox that has a Distinct Row Query from the table that the main table that the form is bound to. It looks for the Sample ID's that are associated with the samples that we test. The list ends at record 87877. We are WAY past that number in our numbering scheme but the list box does not display all the records. When the users type anything over 87877 the auto complete doesn't work and the last record shown in the list is 87877. Does anyone have any idea how to make all records show? The users use this to navigate quickly between samples but now it is broken. Is there some sort of limit?
Thanks
Greg

View 4 Replies View Related

Queries :: Pulling TOP DISTINCT Rows In Final Query

Jun 7, 2013

I've got two nested queries. One finds the oldest inspections from an import table, the second compares that query to the main table again and pulls all 'expired' inspections for each Service Order in the first.

These queries are trimmed down for the essential elements of my question. I can post the full SQL if necessary.

queryDoTheseFirst:

Code:
SELECT TOP 18 ImportTemp.[SO ID], ImportTemp.[Inspection Activity],
[Activity Created]+[AddDays] AS [Due Date]
FROM [Priority List] INNER JOIN (ImportTemp INNER JOIN
queryNeededFirst ON (ImportTemp.[SO ID] = queryNeededFirst.[SO ID])
ON [Priority List].Activity = ImportTemp.[Inspection Activity]

[Code] ....

The refinement I would like to make is, rather than having to pull TOP 18 activities in the final query, just pull TOP 12 [SO ID]s and however many activities come along with them (usually 1 or 2, averages out to about 1.5 so 18 is my compromise). In theory an inspector could have two inspections due on every single property, and would only get 9 unique addresses/[SO ID]s. But I can't figure out how to do that when [SO ID] is no longer unique in the second query.

I suppose I could 'number' the rows in the subquery and add a <=12 criteria on that calculated field, but I'm leery of the processing required (that table contains ~14,000 rows, and most methods of numbering seem to want to use DCount).

View 2 Replies View Related

Need Query For Max Date To Find Most Recent Letter Sent Using Distinct Addresses

Feb 21, 2014

I'm trying to create a report for how many "nasty grams" (rejection notices) my company has sent to people who keep sending in paper forms when they are supposed to file electronically.Every letter that goes out has information recorded based on whatever they sent to us - so the only remotely reliable way to count how many each person received is by the address on the envelope (people use different names, different business names, use different telephone numbers on the forms, etc).

I just built several queries that feed into a report that gets sent to my boss on a monthly basis to show the people who've sent in more than one paper form and have received our rejection notices more than once.I'm not the greatest at SQL, but I've been trying to find a way to use DISTINCT Addresses, leave all other fields the same (not DISTINCT), to:

1. Only return people who have received 2 or more letters

2. If at least one of the letters was sent more than 90 days ago
AND If at least one of the letters was within the last 90 days
-If at least one was within the last 90 days, only display the most recent send date of the letter (lots of people get back-to-back letters).

3. Display their names, addresses, telephone numbers, the date of the most recent letter sent, count of the total letters ever sent to that person. (the report will already do this, just need Max date)

My first query counts the number of times each address appears in the main table and simply only has [Address] and [CountofAddress]

My second query has the [Name], the [LetterDated] >=Now()-90, and the qryCountofAddress is linked to the main table by [Address], using [Countof Address] >=2...I have tried Selecting Unique Values in the Properties tab. Yes, I have tried INNER JOIN (but can't get the rest of my fields to display once I make addresses distinct).

View 1 Replies View Related

Queries :: Count Distinct Error - Missing Operator In Query Expression

Jan 23, 2015

I am trying to get a count of the unique customers in an access 2010 database

After some research it seems i should be using

SELECT Count(Distinct [Customer]) FROM [tblMain];

But when i use this i get

Syntax error (missing operator) in query expression 'Count(Distinct Customer)'.

I have tried leaving out the square brackets but this does not work....

View 3 Replies View Related

Forms :: Remove The DISTINCT From Query And The Detail Section In Form Is Empty?

Nov 13, 2014

i removed the DIsTINCT in my query to move some field to be updateable on the form. Once I did that my detail section of my form was empty ..why and how do I fix this problem.

View 1 Replies View Related

Looking Up A Distinct Value

Aug 28, 2005

I want to count the number of distinct dates in a table. Ie - So I know there were 80 requests over 5 days.

The syntax I imagine is something like:

myText = Dlookup("count(DISTINCT myDate)", "myTable")

Can somebody please help.

Thank you in advance

View 3 Replies View Related

Distinct

Sep 13, 2006

Hi,

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.

How would I go about this.

Any help would be appreciated.

Regards

Matt

View 8 Replies View Related

SQL Distinct

Feb 22, 2007

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.....

View 4 Replies View Related

Count Distinct

Jul 29, 2005

Hi Everyone!,

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??

thanks!,

Sasha

View 2 Replies View Related

Select Distinct

Aug 9, 2005

I need to select two fields in a select DISTINCT query

Select tbl_Aplaws.AplawID, DISTINCT tbl_Aplaws.Level2 FROM tbl_Aplaws WHERE tbl_Aplaws.Level1 = 'Business' ORDER BY tbl_Aplaws.Level2;

anyone know how to make this work?

View 1 Replies View Related

Select Distinct

Sep 13, 2005

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?

View 1 Replies View Related

Distinct Count And Sum

Jan 28, 2007

I have a table like this in MS Access database:

IDDateCustomerIDInvoiceNoItemNoAmount
101/01/2007A1AAA1
201/01/2007A1BBB2
301/01/2007A2CCC3
601/01/2007B5AAA6
701/01/2007A6BBB7
801/01/2007B5BBB8

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? :)


Thanks,

Huyeote

View 5 Replies View Related

Distinct Count

Jun 18, 2007

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"));

Is there a way to do this somehow?

Thanks!

Toni

View 3 Replies View Related

Distinct And DistinctRow

Jun 19, 2007

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;

Thanks in advance!

View 2 Replies View Related

Count/SUM Distinct Help

Jul 6, 2007

I've searched on google for count distinct help but I had no luck. I'm counting 2 different columns and when the query is run the counts in both columns appear exactly the same. Also, I need a SUM distinct (if possible) to sum only where it is being counted in 'CountOfCar_Nr'. Here is my SQL....

View 3 Replies View Related

DISTINCT Question

Jul 12, 2007

Hello


I have a little problem with a query.


There are some tables, one is n:m with the main table.


main_table n:m a_other_table


Now when I run the query, it displays all relations. But I want only the first.


I tried TOP 1 but, this only show 1 record, DISTINCT will not work, I select * from the query.


Now my question, is it possible to DISTINCT only one argument?
I have id's, one id should only appears one time.

Select DISTINCT idAny, * will not work.


Any ideas?

View 5 Replies View Related

DISTINCT Predicate

Aug 31, 2007

All,For some reason, I cannot seem to get a result set with unique records using the DISTINCTROW predicate in Access 2007. However, if I simply use the DISTINCT word (even if I am querying more than one field in a table), the result set gives unique records. This seems backwards....it's certainly not right. I know that the DISTINCTROW predicate does what it's supposed to do in earlier versions of the program, because I use them as well. Does anyone have any ideas on this??Has anyone else experienced this?? Thanks!!

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved