473,792 Members | 2,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to do Max Function on a Subquery

2 New Member
Hi, I've been trying to find and display only the maximum count of a field.
I have two tables;
STUDENT_TABLE - Student ID, Title, Surname and Christan Name.
LESSON_TABLE - Student ID

The two Student IDs are linked. I'm trying to see the Student ID that has occured most in the LESSON_TABLE.

I've figured that, the way I should do this is to use the Count Function on the [LESSON_TABLE].[Student ID] and then the Max function on that. But I don't know how to do that, i've tried to put in

=Max(Count([LESSON_TABLE].[Student ID]))

in the criteria of the field Student ID, but it comes up with an error. I'm thinking the error is saying i'm using too many functions or something? (Error says; "Cannot have aggregate function in expression (LESSON_TABLE.[Student ID] = Max(Count([LESSON_TABLE].[Student ID])))").

How can I use the results of a Subquery in another subquery without making another query?

Please explain what I have to do please, I'm not very good at Access.

I have Access 2010.
Oct 7 '10 #1
4 4373
dsatino
393 Contributor
For starters, there no real reason to avoid building a second query.

Anyway, you can just count the results, sort them descending, and then change your SELECT statement to SELECT TOP 1.

that should do it
Oct 7 '10 #2
NeoPa
32,579 Recognized Expert Moderator MVP
James Tran:
How can I use the results of a Subquery in another subquery without making another query?
This is exactly what you need of course.

The answer can be found in Subqueries in SQL.
Oct 7 '10 #3
James Tran
2 New Member
THANK YOU dsatino, it worked =]

NeoPa, thank you for the link, it is very helpful.
Oct 8 '10 #4
NeoPa
32,579 Recognized Expert Moderator MVP
A pleasure James. Thanks for replying and choosing a Best Answer :-)
Oct 8 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2985
by: Bob M | last post by:
Hi all, I am trying to update a record with a function value. Here is the function: update ITSM_SER_CUSTOM_FIELDS set SCF_SCDATE2 = SLA_PENDING_DATE.GET_DL(2292,'servicecall') where SCF_SER_OID = (select SER_OID from ITSM_SERVICECALLS where SER_ID = 2292);
2
4578
by: lev | last post by:
CREATE TABLE . ( NULL , , (44) ) ID is non-unique. I want to select all IDs where the last entry for that ID is of type 11.
7
9229
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into a table (c) re-queries another table using a subquery which references the inserted table (correlated or not)
0
563
by: Greg Stark | last post by:
Postgresql 7.4b2 (approximately, compiled out of CVS) When I have a subquery that has a complex subquery as one of the result columns, and then that result column is used multiple times in the parent query, the subquery is inlined for each one. This means multiple redundant executions of the subquery. I recall there was a way to defeat this optimization involving introducing an extra subquery layer somewhere. But I'm failing to be able...
11
13514
by: Paul Reddin | last post by:
Hi, This is a real hopeful one! What we are trying to do: 1. We MUST present a mappable database object for our application objects i.e a Table or a View Some of the views are very complex, which raises another couple of
5
2417
by: marcsirois | last post by:
I have an SQL Query that looks like this. I simplified it for the purpose of this example, but it's still a runnable query SELECT TOP 1 FundedPositions.PositionNumber AS , (select top 1 assign_i from dbo_assign a where a.scenario_i=1 and a.assign_i = TestMyFunction(FundedPositions.PositionNumber))AS
5
8036
by: Anne | last post by:
Hello! Here is the statement in question: --STATEMENT A SELECT * FROM dbo.myTable WHERE colX in (SELECT colX FROM dbo.sourceTable) The problem with Statement A is that 'colX' does not exist in 'dbo.sourceTable'. It does, however, certainly exist in 'dbo.myTable'. Breaking the statement down, we have:
1
4171
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only allows me to filter based on variables in a single table. I would like to have a search form where I can select multiple variables (from various linked tables) to filter by, and return results based on this multi-table filter. Allen Browne...
1
7769
NeoPa
by: NeoPa | last post by:
Access QueryDefs Mis-save Subquery SQL Access stores its SQL for Subqueries in a strange manner :s It seems to replace the parentheses "()"with square brackets "" and (often) add an extraneous "." after it. For instance, a simple example illustrates how it works : SELECT subA.* FROM (SELECT , FROM ) AS subA becomes (after saving as a querydef in Access) : SELECT subA.*
2
2632
by: lbseong | last post by:
Hi, I am new to this forum please help. I need to schedule a job to send out an email if found there is a records older than 1 minute (compare to current date time against createddate) and the email will contain the itemid. mytable design 1.) itemid int createddate getdatetime() summaryid varchar startdate datetime enddate datetime
0
9670
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
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
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
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.