473,785 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5294
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 tlkpLocationDir ectory.chrL4Des cription FROM
tlkpLocationDir ectory ORDER BY tlkpLocationDir ectory.chrL4Des cription;

and here is the problematic code:

Me.Form.FilterO n = False
strWhere = "(((tlkpLocatio nDirectory.chrL 2Description)=" "" &
cboL2D.Value & """" & "))"
Me.Form.Filter = strWhere 'at this point the all too hostile enter
parameter box comes up and requests the value of
tlkpLocationDir ectory.chrL2Des cription
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 chrL2Descriptio n.

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
chrL2Descriptio n 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.goo glegroups.com.. .
Right to be more precise with the problem: here is the query
on the form's record source:

SELECT DISTINCT tlkpLocationDir ectory.chrL4Des cription FROM
tlkpLocationDir ectory ORDER BY tlkpLocationDir ectory.chrL4Des cription;

and here is the problematic code:

Me.Form.FilterO n = False
strWhere = "(((tlkpLocatio nDirectory.chrL 2Description)=" "" &
cboL2D.Value & """" & "))"
Me.Form.Filter = strWhere 'at this point the all too hostile enter
parameter box comes up and requests the value of
tlkpLocationDir ectory.chrL2Des cription
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 chrL2Descriptio n a different field than chrL4Descriptio n, or is it
spelled wrong?

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

SELECT DISTINCT tlkpLocationDir ectory.chrL4Des cription FROM
tlkpLocationDir ectory ORDER BY tlkpLocationDir ectory.chrL4Des cription;

and here is the problematic code:

Me.Form.FilterO n = False
strWhere = "(((tlkpLocatio nDirectory.chrL 2Description)=" "" &
cboL2D.Value & """" & "))"
Me.Form.Filter = strWhere 'at this point the all too hostile enter
parameter box comes up and requests the value of
tlkpLocationDir ectory.chrL2Des cription
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 tlkpLocationDir ecotry.L4Descri ption 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******** *************@i 40g2000cwc.goog legroups.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

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

Similar topics

2
1745
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 { font-weight:bold; color:E00000; text-decoration:none } a:visited { font-weight:bold; color:E00000; text-decoration:none } a:hover { font-weight:bold; color:#E00000; text-decoration:none }
1
1991
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 distinct person, title from people where title is null or title is not null " give:
2
3091
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 clause eg SELECT DISTINCT tblPageViews.PageVisited, Count(tblPageViews.PageVisited) AS CountOfPageVisited FROM tblPageViews GROUP BY tblPageViews.PageVisited;
1
2491
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 only way to find out the current state of a particular combination of attributes is to "select distinct on (id, ...) ... order by date desc". In the examples below, I've taken real output from psql and done a global search/replace on various...
15
3624
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 data. It takes about 4 minutes to get the data. In previous versions it was instantaneous. What do I need to do to increase the performance?
5
53479
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" Thanks, Fred Zuckerman
3
1869
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 issue before but I thought the code was fixed. :-( I have the following SQL:
6
2086
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 chooses the department they want and then the corresponding surnames from that department can be chosen from the Surname box and then the Forename depending on which Surname they chose. I then have a command button which produces the results of the...
2
5342
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, middleinitial, address1, address2, city, state, zip, age, gender FROM gpresults
6
2640
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 the fields chosen. The first page, where they select the search fields and submit: <?php $db = mysql_connect("localhost", "root", "yeahright"); if (!$db) { die('Could not connect:'.mysql_error);
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.