473,799 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return only first record in set of records???

This query has been driving me crazy, and would be grateful for a
nudge in the right direction. Still pretty much a beginner using
Access 2003, I just cannot figure the solution to the following in the
query design grid.

I have 4 tables:
tblApplicant Person
Person ID PK

tblCourses Applied
CourseAppID PK
Course ID FK
Person ID FK
Date Created

tblCompendium
Course ID PK
Course Name (text)

tblInterview
InterviewID PK
PersonID FK
Interview Outcome

As you would expect one applicant may apply for 1 or more courses.
However once interviewed they will be given an interview outcome based
their first choice of course. As they can only go on to enrol on one
course.

I need to able to create a query that returns the following fields;
Person ID
Course ID (but only for the first CourseAppID. EG their first choice
of couse)
Course Name
Interview Outcome (text)

I have tried using 'First' in the totals field of the QBE, but I dont
think this is the correct use of this. I would really appreciate a
nudge in the right direction.
Many thanks
Carl

Mar 15 '07 #1
6 9893
Use a subquery to select what their first choice is. You can then build
another query based on the results to get all the other fields you want.

The first query will be something like this (though I'm not clear how you
choose the "first" choice):

SELECT [tblApplicant Person].*,
(SELECT TOP 1 [Course ID]
FROM [tblApplication Person]
WHERE [tblApplication Person].[Person ID] =
[tblApplication Person].[Person ID]
ORDER BY [tblApplication Person].[Date Created],
[tblApplication Person].CourseAppID)
FROM [tblApplicant Person];

If subqueries are new, see:
http://allenbrowne.com/subquery-01.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"zack" <za******@yahoo .co.ukwrote in message
news:11******** ************@b7 5g2000hsg.googl egroups.com...
This query has been driving me crazy, and would be grateful for a
nudge in the right direction. Still pretty much a beginner using
Access 2003, I just cannot figure the solution to the following in the
query design grid.

I have 4 tables:
tblApplicant Person
Person ID PK

tblCourses Applied
CourseAppID PK
Course ID FK
Person ID FK
Date Created

tblCompendium
Course ID PK
Course Name (text)

tblInterview
InterviewID PK
PersonID FK
Interview Outcome

As you would expect one applicant may apply for 1 or more courses.
However once interviewed they will be given an interview outcome based
their first choice of course. As they can only go on to enrol on one
course.

I need to able to create a query that returns the following fields;
Person ID
Course ID (but only for the first CourseAppID. EG their first choice
of couse)
Course Name
Interview Outcome (text)

I have tried using 'First' in the totals field of the QBE, but I dont
think this is the correct use of this. I would really appreciate a
nudge in the right direction.
Many thanks
Carl
Mar 15 '07 #2
GH
Zack,

Depending on your exact result needs, you can accomplish your
requirement a couple of ways. If you really only want ONE record to
be returned, use the MIN([Date Created]), assuming this is the field
that determines which course was chosen as a first choice. If you want
all records, but need the first choice to be at the top, you can sort
your query results using the ORDER BY clause (Sort: if you are using
query designer). If you sort by [Date Created] Ascending, the
earliest date will be first in the record set. If you are also
pulling more than one individual in your results, just sort by the
[Person ID] then the [Date Created]. You can sort and limit your query
results by this date, even if you do not want the date to be part of
the query results by unchecking the Show checkbox for that field.
Hope this helps you solve your dilemma. Good luck!

- GH

On Mar 15, 7:06 am, "zack" <zack6...@yahoo .co.ukwrote:
This query has been driving me crazy, and would be grateful for a
nudge in the right direction. Still pretty much a beginner using
Access 2003, I just cannot figure the solution to the following in the
query design grid.

I have 4 tables:
tblApplicant Person
Person ID PK

tblCourses Applied
CourseAppID PK
Course ID FK
Person ID FK
Date Created

tblCompendium
Course ID PK
Course Name (text)

tblInterview
InterviewID PK
PersonID FK
Interview Outcome

As you would expect one applicant may apply for 1 or more courses.
However once interviewed they will be given an interview outcome based
their first choice of course. As they can only go on to enrol on one
course.

I need to able to create a query that returns the following fields;
Person ID
Course ID (but only for the first CourseAppID. EG their first choice
of couse)
Course Name
Interview Outcome (text)

I have tried using 'First' in the totals field of the QBE, but I dont
think this is the correct use of this. I would really appreciate a
nudge in the right direction.
Many thanks
Carl

Mar 15 '07 #3

>
Depending on your exact result needs, you can accomplish your
requirement a couple of ways. If you really only want ONE record to
be returned, use the MIN([Date Created]), assuming this is the field
that determines which course was chosen as a first choice. If you want
all records, but need the first choice to be at the top, you can sort
your query results using the ORDER BY clause (Sort: if you are using
query designer). If you sort by [Date Created] Ascending, the
earliest date will be first in the record set. If you are also
pulling more than one individual in your results, just sort by the
[Person ID] then the [Date Created]. You can sort and limit your query
results by this date, even if you do not want the date to be part of
the query results by unchecking the Show checkbox for that field.
Hope this helps you solve your dilemma. Good luck!

- GH
>

This query has been driving me crazy, and would be grateful for a
nudge in the right direction. Still pretty much a beginner using
Access 2003, I just cannot figure the solution to the following in the
query design grid.
I have 4 tables:
tblApplicant Person
Person ID PK
tblCourses Applied
CourseAppID PK
Course ID FK
Person ID FK
Date Created
tblCompendium
Course ID PK
Course Name (text)
tblInterview
InterviewID PK
PersonID FK
Interview Outcome
As you would expect one applicant may apply for 1 or more courses.
However once interviewed they will be given an interview outcome based
their first choice of course. As they can only go on to enrol on one
course.
I need to able to create a query that returns the following fields;
Person ID
Course ID (but only for the first CourseAppID. EG their first choice
of couse)
Course Name
Interview Outcome (text)
I have tried using 'First' in the totals field of the QBE, but I dont
think this is the correct use of this. I would really appreciate a
nudge in the right direction.
Many thanks
Carl- Hide quoted text -

- Show quoted text -
Many thanks for the suggestions.
Your correct I am looking for 1 applicant, 1 course (their first
choice, using data created) and 1 interview outcome.
I am still stuck as 'Min' is still bringing back all the applicants
course choices.
Any other suggestions to move forward with this. for the sake of my
sanity HELP!!

Mar 15 '07 #4
On Mar 15, 12:06 pm, "zack" <zack6...@yahoo .co.ukwrote:
I am looking for 1 applicant, 1 course (their first
choice, using data created) and 1 interview outcome.
How do you determine the applicant's first choice course? Shouldn't
there be a column in the tblInterview table to show this?

Jamie.

--
Mar 15 '07 #5
GH
Zack,

If I am understanding correctly, your query is missing one last
element, which is a parameter or that narrows down to the selected
applicant. If you are accessing the query through a form, the form
can filter on the Person ID. If you are manually inputting a person's
ID, you can just add a WHERE clause that prompts the user for Person
ID. A simplistic test of this is to add WHERE [Person ID] = ? and
Access will prompt the user to enter the value for ?, then only the
record for the entered person would be included in the recordset.

If the issue is actually that you are getting all records for a single
applicant, this could be due to the need to make sure your criteria
has the [Date Created] = to the Min([Date Created]). This will ensure
only one course record returns, the one with the minimum date.
Alternatively, you can use Allen Browne's suggestion because it pulls
only the first record, and sorting by date ensures the earliest date
is the first record.

- GH
>...
Many thanks for the suggestions.
Your correct I am looking for 1 applicant, 1 course (their first
choice, using data created) and 1 interview outcome.
I am still stuck as 'Min' is still bringing back all the applicants
course choices.
Any other suggestions to move forward with this. for the sake of my
sanity HELP!!- Hide quoted text -

- Show quoted text -

Mar 15 '07 #6
GH
I forgot to add that if the same create date is possible for a single
person, you could still get too many records using MIN, but you might
not necessarily get the correct record using Top 1 either if there is
no way to differentiate which course actually got created first.

- GH

On Mar 15, 8:06 am, "zack" <zack6...@yahoo .co.ukwrote:
>
...
Many thanks for the suggestions.
Your correct I am looking for 1 applicant, 1 course (their first
choice, using data created) and 1 interview outcome.
I am still stuck as 'Min' is still bringing back all the applicants
course choices.
Any other suggestions to move forward with this. for the sake of my
sanity HELP!!- Hide quoted text -

- Show quoted text -

Mar 15 '07 #7

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

Similar topics

17
4478
by: Rick | last post by:
Hi all, Is there a MySQL function to get the first record through a query? I would like to open a page of client records with the first one shown. The other records can be accessed from a hyperlinked list. Thanks for any advice, Rick
10
12845
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following SQL commands will return the same result but one of my friends don't think so. He said "QUERY 1" will return 1 unsorted record (ROWNUM < 2 ) first then sort the result (ORDER BY COL1 ASC,
20
10684
by: MS | last post by:
Access 97 I want to requery the data being displayed on a form, then I want to return to the record I was in. Why doesn't this code work? Private Sub CmdRefsh_Click()
1
1407
by: David | last post by:
Hi, I have a problem with returning a value from an external function..... My asp page is basically a list taken from a database. A date record is written from the DB, then all the recordslinked to that date are listed, then the next date, then the next series of records, i.e.
2
2752
by: jennk | last post by:
i am working in Access 97, our database tables are linked from ODBCsqlsvr (not even sure what that means). i have a table where each record has a unique customer and their order information. there are 20 possible items to be ordered. i need a query that will return a unique row for every item ordered. if the same customer (record) orders 3 items, i need the query to return 3 rows. Each row will have the same customer info (name, address,...
2
2341
by: Wayne | last post by:
Is there a workaround to the bug that loses the first record in a continuous form after using the scroll wheel if the available records don't fill the form? I know that the "up arrow" section of the scrollbar can be clicked to show the record again but this is hardly intuitive to the user. Any help is appreciated.
3
2428
by: brucedodds | last post by:
My application has a form based on a parent table with a subform based on a child table. The relationship is Cascade Delete. The first record displayed when the form opens has five child records. The form allows this record to be deleted without a prompt, though SetWarnings is set to True. When you try to delete other records, you do get a prompt. The problem isn't the relationship or the tables, because a test form/ subform using the...
2
3557
Zwoker
by: Zwoker | last post by:
Greetings everyone, I have a problem that I hope has a simple solution. I am using MS Access 2003. I have a table that is a list of financial transactions. I am using a make table query over that table, and want to return a single record where multiple exist for the five fields that are keys on the table. The rule as to which record I want returned where many exist is to use the record with the most recent transaction date (a field on the...
7
3735
by: Wildster | last post by:
Hi, I’ve setup a table which contains records with multiple duplicated time fields (tblTime_Slots) i.e. ID Time_Slot 1 08:00 2 08:00 3 09:00 4 09:00 etc…
0
9687
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
9541
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
10485
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
10252
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
10231
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
9073
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...
0
5463
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
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

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.