Query For Getting ID Degree (1 Viewer)

Jonny

Registered User.
Local time
Today, 16:07
Joined
Aug 12, 2005
Messages
144
Having a table DegreeDate
Fields are : ID, DegreeDate, Degree.

Each ID may have more than one degree.

Wish to build a query that shows only those whose degree is 50.
If same ID has higher degree he will not be shown.

Will appreciate your help..
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:07
Joined
Oct 29, 2018
Messages
21,582
Hi. Did you try putting a criteria of 50 under the Degree column?
 

Jonny

Registered User.
Local time
Today, 16:07
Joined
Aug 12, 2005
Messages
144
Hi. Did you try putting a criteria of 50 under the Degree column?

Yes, but I want to get only those records where 50 is the higher degree.
If same ID has 60, 70, e.t.c not to show also 50.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:07
Joined
Oct 29, 2018
Messages
21,582
Yes, but I want to get only those records where 50 is the higher degree.
If same ID has 60, 70, e.t.c not to show also 50.
I see. Maybe something like:
Code:
SELECT T1.* FROM TableName T1
INNER JOIN (SELECT T2.ID, Max(Degree) AS M
FROM TableName T2
GROUP BY T2.ID
HAVING Max(Degree)=50) SQ
ON T1.ID=SQ.ID
WHERE T1.Degree=50
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:07
Joined
Sep 21, 2011
Messages
14,536
This method will do it. It shows me the highest amount for a client, with the lowest value being £500. If higher, that is shown instead.

Code:
SELECT Transactions.Description, Max(Transactions.Amount) AS MaxOfAmount
FROM Transactions
GROUP BY Transactions.Description
HAVING (((Max(Transactions.Amount))>=500));
 

Jonny

Registered User.
Local time
Today, 16:07
Joined
Aug 12, 2005
Messages
144
I'm a newbie in Access, may you add a screenshot how it looks in Access (not SQL).
Sorry for that..
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:07
Joined
Oct 29, 2018
Messages
21,582
I'm a newbie in Access, may you add a screenshot how it looks in Access (not SQL).
Sorry for that..
Instead, are you able to post a small copy of your db with test data?
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:07
Joined
Sep 21, 2011
Messages
14,536
I'm a newbie in Access, may you add a screenshot how it looks in Access (not SQL).
Sorry for that..

Ok, here it is

 

Attachments

  • Max Query.PNG
    Max Query.PNG
    11.7 KB · Views: 157
Last edited:

Jonny

Registered User.
Local time
Today, 16:07
Joined
Aug 12, 2005
Messages
144
Instead, are you able to post a small copy of your db with test data?
Hereby please find attached,
Let's assume I'm putting "23" in Degree, then I don't want John to be shown as he has also 76.
Hoping it's clear..
 

Attachments

  • test1.accdb
    412 KB · Views: 39

theDBguy

I’m here to help
Staff member
Local time
Today, 06:07
Joined
Oct 29, 2018
Messages
21,582
Hereby please find attached,
Let's assume I'm putting "23" in Degree, then I don't want John to be shown as he has also 76.
Hoping it's clear..
Hi. Thanks, but I am not sure I understand. Here's a screenshot of your data.



So, if we use 23 for a Degree criteria, which records should show up in the result? Everybody but John? Or no one?
 

Attachments

  • john.png
    john.png
    15.2 KB · Views: 177

Jonny

Registered User.
Local time
Today, 16:07
Joined
Aug 12, 2005
Messages
144
Hi. Thanks, but I am not sure I understand. Here's a screenshot of your data.



So, if we use 23 for a Degree criteria, which records should show up in the result? Everybody but John? Or no one?

In this particular case nothing.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:07
Joined
Oct 29, 2018
Messages
21,582
In this particular case nothing.
Okay, not sure it completely clarifies the ultimate intent, but I added a couple more records, since I want to make sure the query will return something acceptable other than nothing. Please let me know if this is anywhere close to what you want.


1. Open Table1 to review the two records I added
2. Open Query2 to see the result


If the result is correct for Degree of 23, then I think we can move on. If not, then please let us know why not and how else to move forward.


Thanks.
 

Attachments

  • test1.zip
    19.2 KB · Views: 49

Gasman

Enthusiastic Amateur
Local time
Today, 14:07
Joined
Sep 21, 2011
Messages
14,536
Hereby please find attached,
Let's assume I'm putting "23" in Degree, then I don't want John to be shown as he has also 76.
Hoping it's clear..

Well my idea would not work,as it would show 76. :(

Sorry I misunderstood your initial post.
 

June7

AWF VIP
Local time
Today, 05:07
Joined
Mar 9, 2014
Messages
5,501
Consider:

SELECT Table1.*
FROM Table1
WHERE Table1.Degree=[enter value] AND FirstName NOT IN(SELECT FirstName FROM Table1 WHERE Degree>[enter value]);
 

Jonny

Registered User.
Local time
Today, 16:07
Joined
Aug 12, 2005
Messages
144
Hi. Thanks, but I am not sure I understand. Here's a screenshot of your data.



So, if we use 23 for a Degree criteria, which records should show up in the result? Everybody but John? Or no one?

Okay, not sure it completely clarifies the ultimate intent, but I added a couple more records, since I want to make sure the query will return something acceptable other than nothing. Please let me know if this is anywhere close to what you want.


1. Open Table1 to review the two records I added
2. Open Query2 to see the result


If the result is correct for Degree of 23, then I think we can move on. If not, then please let us know why not and how else to move forward.


Thanks.

This one partially did the job, however when I put also DegreeDate column it shows me non-relevant record as well?!
 

Attachments

  • Capture.JPG
    Capture.JPG
    24 KB · Views: 33
  • 12222.JPG
    12222.JPG
    18 KB · Views: 44
Last edited:

Jonny

Registered User.
Local time
Today, 16:07
Joined
Aug 12, 2005
Messages
144
I've marked DegreeDate as Max and it solved the issue.

Thank you, guys, for your help!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:07
Joined
Oct 29, 2018
Messages
21,582
Hi. Why are you modifying Query1? Has the intent changed? I asked you to open Query2 and verify its result. What are you trying to accomplish by adding the date column in Query1?
 

Jonny

Registered User.
Local time
Today, 16:07
Joined
Aug 12, 2005
Messages
144
Hi. Why are you modifying Query1? Has the intent changed? I asked you to open Query2 and verify its result. What are you trying to accomplish by adding the date column in Query1?
I took your solution , however when I was trying to add DegreeDate column the output was changed.
Apparently I was missing to add "Max" also to that column.
 

Users who are viewing this thread

Top Bottom