473,395 Members | 1,986 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.

Select distict and order by in a combo box

Hi,
The line below is used to feed a combobox. (It is from a database which is
used to log pupil behaviour!) The 'incidents' table contains a list of
students who have been involved in incidents. Some may appear several
times, hence the Distinct. However, thelist generated should still be
sorted by Surname. When I add Order by [Surname] I'm told it conflict with
the 'Distinct'. Surely it does not?

SELECT DISTINCT [Incidents].[StudentId], [Incidents].[Surname] & " " &
[Incidents].[Forename] FROM Incidents WHERE [Surname]>"";

Thanks in advance

John M
Nov 12 '05 #1
6 5526
It should be possible. What's the SQL you're trying to use?

It should be
SELECT DISTINCT [Incidents].[StudentId], [Incidents].[Surname] & " " &
[Incidents].[Forename] FROM Incidents WHERE [Surname]>""
ORDER BY [Surname]
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"John M" <jo**@jmawer.demon.co.uk> wrote in message
news:c0*******************@news.demon.co.uk...
Hi,
The line below is used to feed a combobox. (It is from a database which is
used to log pupil behaviour!) The 'incidents' table contains a list of
students who have been involved in incidents. Some may appear several
times, hence the Distinct. However, thelist generated should still be
sorted by Surname. When I add Order by [Surname] I'm told it conflict with the 'Distinct'. Surely it does not?

SELECT DISTINCT [Incidents].[StudentId], [Incidents].[Surname] & " " &
[Incidents].[Forename] FROM Incidents WHERE [Surname]>"";

Thanks in advance

John M

Nov 12 '05 #2
Thanks .....

That's what I had a go at, but I get the error message 'Order by clause
([Surname]) conflicts with distinct'
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:kl******************@twister01.bloor.is.net.c able.rogers.com...
It should be possible. What's the SQL you're trying to use?

It should be
SELECT DISTINCT [Incidents].[StudentId], [Incidents].[Surname] & " " &
[Incidents].[Forename] FROM Incidents WHERE [Surname]>""
ORDER BY [Surname]
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"John M" <jo**@jmawer.demon.co.uk> wrote in message
news:c0*******************@news.demon.co.uk...
Hi,
The line below is used to feed a combobox. (It is from a database which is used to log pupil behaviour!) The 'incidents' table contains a list of
students who have been involved in incidents. Some may appear several
times, hence the Distinct. However, thelist generated should still be
sorted by Surname. When I add Order by [Surname] I'm told it conflict

with
the 'Distinct'. Surely it does not?

SELECT DISTINCT [Incidents].[StudentId], [Incidents].[Surname] & " " &
[Incidents].[Forename] FROM Incidents WHERE [Surname]>"";

Thanks in advance

John M


Nov 12 '05 #3
John M wrote:
Thanks .....

That's what I had a go at, but I get the error message 'Order by clause
([Surname]) conflicts with distinct'

This is Access dialect. Either include Surname as separate field, or
ORDER BY the same expression as you SELECT:

ORDER BY [Incidents].[Surname] & " " & [Incidents].[Forename]

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Nov 12 '05 #4
I have just tried the same expression as the SELECT. Same result. I thne
tried sorting on a different field (YearGrp) in the same table but not used
in the select, and the same result. I've also cut and paste from a query in
which I call Surname and Forename AllName. In this too the conflict arises.

Despite your help, i'm lost!!

"Bas Cost Budde" <ba*@heuveltop.org> wrote in message
news:c0**********@news2.solcon.nl...
John M wrote:
Thanks .....

That's what I had a go at, but I get the error message 'Order by clause
([Surname]) conflicts with distinct'

This is Access dialect. Either include Surname as separate field, or
ORDER BY the same expression as you SELECT:

ORDER BY [Incidents].[Surname] & " " & [Incidents].[Forename]

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Nov 12 '05 #5
John M wrote:
I have just tried the same expression as the SELECT. Same result. I thne
tried sorting on a different field (YearGrp) in the same table but not used
in the select, and the same result. I've also cut and paste from a query in
which I call Surname and Forename AllName. In this too the conflict arises.

Despite your help, i'm lost!!


Then, by all means do a Totals query and group on the name expression.

(No, I can't stand this)

The Help says:
U hebt een SQL-instructie gemaakt met een predikaat ALL, DISTINCT of
DISTINCTROW en een component ORDER BY die een veld bevat dat niet
voorkomt in de instructie SELECT. Verwijder het gereserveerde woord
DISTINCT, of verwijder het opgegeven veld uit de component ORDER BY.

(that's Dutch! Let's try to translate)

You created a SQL instruction with a predicate ALL, DISTINCT or
DISTINCTROW and a component ORDER BY with a field that is not in the
SELECT instruction. Remove the word DISTINCT or remove the field from
the component ORDER BY.

With this information, I removed Surname from the ORDER BY. This is my
result that runs without error:

SELECT DISTINCT Incidents.StudentID, [Incidents].[Surname] & " " &
[Incidents].[Forename] AS Expr1
FROM Incidents
WHERE (((Incidents.Surname)>""))
ORDER BY [Incidents].[Surname] & " " & [Incidents].[Forename];

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Nov 12 '05 #6
I think my last message was not delivered. If it was, apologies for the
duplication.

Excellent - problem solved - many thanks. I still don't understand it, it
seems to hang around the 'Where' clause and the brackets. That is the only
difference between what you sent me and attempts I have made. (So somewhere
it is still a challenge.

Thanks again

John M
"Bas Cost Budde" <ba*@heuveltop.org> wrote in message
news:c0*********@news2.solcon.nl...
John M wrote:
I have just tried the same expression as the SELECT. Same result. I thne tried sorting on a different field (YearGrp) in the same table but not used in the select, and the same result. I've also cut and paste from a query in which I call Surname and Forename AllName. In this too the conflict arises.
Despite your help, i'm lost!!


Then, by all means do a Totals query and group on the name expression.

(No, I can't stand this)

The Help says:
U hebt een SQL-instructie gemaakt met een predikaat ALL, DISTINCT of
DISTINCTROW en een component ORDER BY die een veld bevat dat niet
voorkomt in de instructie SELECT. Verwijder het gereserveerde woord
DISTINCT, of verwijder het opgegeven veld uit de component ORDER BY.

(that's Dutch! Let's try to translate)

You created a SQL instruction with a predicate ALL, DISTINCT or
DISTINCTROW and a component ORDER BY with a field that is not in the
SELECT instruction. Remove the word DISTINCT or remove the field from
the component ORDER BY.

With this information, I removed Surname from the ORDER BY. This is my
result that runs without error:

SELECT DISTINCT Incidents.StudentID, [Incidents].[Surname] & " " &
[Incidents].[Forename] AS Expr1
FROM Incidents
WHERE (((Incidents.Surname)>""))
ORDER BY [Incidents].[Surname] & " " & [Incidents].[Forename];

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Nov 12 '05 #7

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

Similar topics

1
by: leegold2 | last post by:
say I'm selecting distinct (non-duplicate) rows for insertion, insert into original_table select distinct * from new_table these tables have 3 fields/row. Per the above code all 3 fields are...
14
by: Jos? | last post by:
This one droves me completely mad. I did not succeed to exploit the track given to me by Bob. I have : three tables : Clubs, Persons and ClubsPersons that join the two first in a many to many...
8
by: skinnybloke | last post by:
Hi - I have a problem with a memo field being truncated to about 255 characters when running a Access 2002 query. This only seems to happen if I use SELECT DISTINCT. It works ok using SELECT by...
2
by: TD | last post by:
I have this expression in the criteria section of a query: IIf(Forms!frmReports!cboProductID="<ALL PRODUCTS>",. Like "*",Forms!frmReports!cboProductID) (the syntax of the above expression may...
3
by: Nick Douglas | last post by:
I have a table with 50 fields, and a combo box which is set to 'field list' to read the field names. I want to select report groups via another combo box based on the field names the user selects....
9
by: Vmusic | last post by:
Hi, I'm using MS Access 2002. I have a form with a combo box built from a query that returns one column, and that one column is the bound column. How do you use VBA to programmatically change...
6
by: alex.kemsley | last post by:
Hi guys, I have the following sql statemant to search a mysql database that gets if values from a form with combo box's in. SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =...
1
by: ebo2006 | last post by:
There are two combo boxes in my form: CORP and CLASS. The WHERE clause of the SELECT statement in the Row Source Property of the CLASS combo box works only every time I start the form. It does not...
10
by: BeaBea | last post by:
Hi All, I have been reading some of the threads in your forum and decided to join and post my question. Hopefully it won't be too lengthy. I have created an Unbound Form called paramform2. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...

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.