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

Problem with DISTINCT query ?

Hello Folks,
can anybody tell me how to do the following very simple thing:
I have a table that has say departments, divisions and units of an
organisation and what i am trying to do is find a divison. One
department has many divisions, and one division many units. I am think
therefore a SELECT DISTINCT query on the division would make sense and
to put my search criteria for department on the WHERE. Of course that
doesnt work since you need the where clause to refer to a field in the
SELECT DISTINCT clause and if I put the field there it would make that
distinct as well. I know it must be simple but i acnnot figure out how
to do it.

May 10 '06 #1
10 5267
In fact I can put the criteria in the WHERE even if they dont appear in
the SELECT (i just tried it in access Query design). Why then does it
not work when I put exactly the same in me.form.filter ??? (and it is
not the filteron = true or the quotation marks)

May 10 '06 #2
Right to be more precise with the problem: here is the query
on the form's record source:

SELECT DISTINCT tlkpLocationDirectory.chrL4Description FROM
tlkpLocationDirectory ORDER BY tlkpLocationDirectory.chrL4Description;

and here is the problematic code:

Me.Form.FilterOn = False
strWhere = "(((tlkpLocationDirectory.chrL2Description)="" " &
cboL2D.Value & """" & "))"
Me.Form.Filter = strWhere 'at this point the all too hostile enter
parameter box comes up and requests the value of
tlkpLocationDirectory.chrL2Description
Me.FilterOn = True
What did i do wrong? I got the query from the query design and it was
running.

May 10 '06 #3
The problem is that your form's recordset does not contain chrL2Description.

In another of your posts you say that this works in a query. That's because
the recordset for the query is the table, and so any of its fields are
available. In your form, you've limited the recordset to a single field,
and that's all that it knows about. To get it to work, you must include
chrL2Description in the form's recordset. The field does not need to be
displayed on the form; but it does need to be in the form's recordset.

HTH,

Rob

"Farmer" <kn******@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
Right to be more precise with the problem: here is the query
on the form's record source:

SELECT DISTINCT tlkpLocationDirectory.chrL4Description FROM
tlkpLocationDirectory ORDER BY tlkpLocationDirectory.chrL4Description;

and here is the problematic code:

Me.Form.FilterOn = False
strWhere = "(((tlkpLocationDirectory.chrL2Description)="" " &
cboL2D.Value & """" & "))"
Me.Form.Filter = strWhere 'at this point the all too hostile enter
parameter box comes up and requests the value of
tlkpLocationDirectory.chrL2Description
Me.FilterOn = True
What did i do wrong? I got the query from the query design and it was
running.

May 10 '06 #4
Is chrL2Description a different field than chrL4Description, or is it
spelled wrong?

"Farmer" <kn******@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
Right to be more precise with the problem: here is the query
on the form's record source:

SELECT DISTINCT tlkpLocationDirectory.chrL4Description FROM
tlkpLocationDirectory ORDER BY tlkpLocationDirectory.chrL4Description;

and here is the problematic code:

Me.Form.FilterOn = False
strWhere = "(((tlkpLocationDirectory.chrL2Description)="" " &
cboL2D.Value & """" & "))"
Me.Form.Filter = strWhere 'at this point the all too hostile enter
parameter box comes up and requests the value of
tlkpLocationDirectory.chrL2Description
Me.FilterOn = True
What did i do wrong? I got the query from the query design and it was
running.

May 10 '06 #5
L2 stands for level 2 (deparment) and L4 level 4 (branch)

May 10 '06 #6
Thank you Rob for your reply, if I did that then L2Descriprion would de
"DISTINCT" and I don't want it to be

May 10 '06 #7
And also in the query it was the exact same query that worked i.e.
SELECT DISTINCT tlkpLocationDirecotry.L4Description FROM...

May 10 '06 #8
You know something Rob...
You are absolutely right and I made a silly mistake. The mistake is: If
you make a SELECT DISTINCT query on two field it will return the pair
once and not each field once. Of course that is the only way it makes
sense otherwise you would not get meaningful results. I did not
understand that very well until now, it is my first Access program.

May 10 '06 #9
Glad you've got it!

Rob

"Farmer" <kn******@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
You know something Rob...
You are absolutely right and I made a silly mistake. The mistake is: If
you make a SELECT DISTINCT query on two field it will return the pair
once and not each field once. Of course that is the only way it makes
sense otherwise you would not get meaningful results. I did not
understand that very well until now, it is my first Access program.

May 10 '06 #10
"Farmer" <kn******@gmail.com> wrote in
news:11**********************@e56g2000cwe.googlegr oups.com:

[the first of a half dozen posts threading out the description of
the problem over several articles]

Next time you want help, pause and think about how to describe it.
Then write ONE POST describing the whole problem.

Any time I see a thread with a chain of posts from the original
poster, I skip to the next thread, because I just don't have time to
sort through the confusion of assembling the multiple posts into a
coherent description of the problem.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
May 10 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: justme | last post by:
Dears I have created the following page to display my data <head> <style type="text/css"> body, td, th, h1, h2 {font-family: sans-serif;} body, td, th {font-size: 100%;} a:link {...
1
by: Vince | last post by:
I have several questions about queries I make into my database. I will explain you. Could you please help me? 1)In my people table, persons have a title (Mr, Miss, or whatever). " select...
2
by: Paxton | last post by:
Hi, I'm trying to display the total page views per page within a given date range, but the correct SQL is seemingly beyond me. I get the correct result with a straightforward Group By and Count...
1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
15
by: Hemant Shah | last post by:
Folks, We have an SQL statement that was coded in an application many years ago (starting with DB V2 I think). When I upgraded to UDB 8.2, the optimizer does not use optimal path to access the...
5
by: Fred Zuckerman | last post by:
Can someone explain the difference between these 2 queries? "Select Distinct id, account, lastname, firstname from table1" and "Select DistinctRow id, account, lastname, firstname from table1" ...
3
by: Sean Shanny | last post by:
To all, We are running postgresql 7.4.1 on an G5 with dual procs, OSX 10.3.3 server, 8GB mem, attached to a fully configured 3.5TB XRaid box via fibre channel. I think we have run into this...
6
by: visionstate | last post by:
Hi there, I am building a database that requires cascading lists on a form. I currently have (I may be adding more later) 3 combo boxes on my form - Department, Surname and Forename. The user...
2
by: Techhead | last post by:
I need to run a SELECT DISTINCT query across multiple fields, but I need to add another field that is NON-DISTINCT to my record set. Here is my query: SELECT DISTINCT lastname, firstname,...
6
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.