[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Where/Having Question

Posted on 2001-06-05
13
Medium Priority
?
197 Views
Last Modified: 2006-11-17
I want to limit a query to a maximum date entered..

I would like to say .. where myDateField = max(mydatefield)

How can I use a function like MAX in a where clause or having clause .. I have tried different sytaxes with no luck.  Im sure its easy..I am actually using it in Access but figured it was more of an SQL question
0
Comment
Question by:kiprimshot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 6157056
Try:

... WHERE myDateField = (Select Max(myDateField) FROM MyFile)
0
 
LVL 2

Author Comment

by:kiprimshot
ID: 6157092
The problem with that is that it only returns the max date of one record..
right now without the where clause I am getting the max date for each individual...

I want to continue with that ...

I hope that makes sense
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6157116
so how about a little subquery then?

select * from MyTable WHERE MyDateField < (SELECT MAX(MyOtherDateField) FROM SomeOtherTable)

would that work???

i'll check the syntax and get back to you...

dovholuk
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:dovholuk
ID: 6157125
yeah, that'll work.

use a subquery as above

need more help?

dovholuk
0
 
LVL 32

Accepted Solution

by:
Brendt Hess earned 200 total points
ID: 6157141
You can modify the Subquery to refer to the ID for each individual, e.g.:

... WHERE myDateField = (Select Max(X.myDateField) FROM MyFile AS X WHERE X.ID = MyFile.ID)

In this case, MyFile.ID refers to the ID of the main recordset.  
0
 
LVL 2

Author Comment

by:kiprimshot
ID: 6157146
isnt that the same as what bhess suggested?  Maybe Im misunderstanding..
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6157186
kiprimshot,

yes, pretty much. i read your response without reading bhess' and i jumped the gun a bit. but i also changed the = sign to a < sign, which will give you all the records up to that date.

it's still the same basic idea though, but i thought you were looking for the records up to/ including that Max date.

my apologies if i recycled a response.

dovholuk
0
 
LVL 54

Expert Comment

by:nico5038
ID: 6157224
Just a little remark, is the Time included in the date field.... ?

Nic;o)
0
 
LVL 2

Author Comment

by:kiprimshot
ID: 6157230
no time
0
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 6157313
Question:  Did you try the second query example I provided above?  Does it do what you need?
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6157315
kiprimshot,

either my query or bhess' should do what you're looking for.  have you tried them?

if you didn't get what you needed, please let us know.

dovholuk
0
 
LVL 2

Author Comment

by:kiprimshot
ID: 6157424
I will try it sometime this afternoon
0
 
LVL 2

Author Comment

by:kiprimshot
ID: 6157981
I should have been able to figure this out..
Thanks to both of you for your help.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question