
28-Jul-2006, 08:07 AM
|  | Guest | | | | | | | | | | RE: query help - retrieve only those with highest value Also, just to clarify this is an *additional* constraint to one I already
have in the query. That is, I want only those results where *both* conditions
are met.
Firstly, where ContractEndDate>=Date() Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
Secondly, where (having met the above condition), VarNo is the highest
TIA
"access user" wrote:
> I have a query and I wish to restrict the returned values to only those Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
> where, for a particular field, the value is the highest.
>
> For example, a property can have had a number of rent agreements but, in the
> following example, I don't want ALL the records, just the one where VarNo is
> the highest
>
> PropertyNo TenantNo VarNo
> 1 1 1
> 1 1 2
> 1 2 3
>
> I *only* want the last line not all three lines.
>
> TIA
> James | 
28-Jul-2006, 08:08 AM
|  | Guest | | | | | | | | | | Re: query help - retrieve only those with highest value 123456
"access user" wrote in message
news:FBCDD485-AAFA-4E68-9E52-11919E664093@microsoft.com...
> Also, just to clarify this is an *additional* constraint to one I already
> have in the query. That is, I want only those results where *both*
> conditions
> are met.
> Firstly, where ContractEndDate>=Date()
> Secondly, where (having met the above condition), VarNo is the highest
>
> TIA
>
> "access user" wrote:
>
>> I have a query and I wish to restrict the returned values to only those
>> where, for a particular field, the value is the highest.
>>
>> For example, a property can have had a number of rent agreements but, in
>> the
>> following example, I don't want ALL the records, just the one where VarNo
>> is
>> the highest
>>
>> PropertyNo TenantNo VarNo
>> 1 1 1
>> 1 1 2 Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
>> 1 2 3
>>
>> I *only* want the last line not all three lines. Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
>>
>> TIA
>> James | 
28-Jul-2006, 08:08 AM
|  | Guest | | | | | | | | | | RE: query help - retrieve only those with highest value Hi.
Assuming the name of your table is "TableName", try this:
SELECT TableName.PropertyNo, TableName.TenantNo, TableName.VarNo
FROM TableName
WHERE (TableName.VarNo)=(SELECT Max(VarNo) AS MaxVarNo FROM TableName WHERE
(TableName.ContractEndDate)>=Date());
-Michael
"access user" wrote:
> Also, just to clarify this is an *additional* constraint to one I already
> have in the query. That is, I want only those results where *both* conditions
> are met.
> Firstly, where ContractEndDate>=Date()
> Secondly, where (having met the above condition), VarNo is the highest
>
> TIA
>
> "access user" wrote:
>
> > I have a query and I wish to restrict the returned values to only those
> > where, for a particular field, the value is the highest.
> >
> > For example, a property can have had a number of rent agreements but, in the
> > following example, I don't want ALL the records, just the one where VarNo is Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869 Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
> > the highest
> >
> > PropertyNo TenantNo VarNo
> > 1 1 1
> > 1 1 2
> > 1 2 3
> >
> > I *only* want the last line not all three lines.
> >
> > TIA
> > James | 
28-Jul-2006, 08:08 AM
|  | Guest | | | | | | | | | | RE: query help - retrieve only those with highest value In your query you could try putting VarNo field in Descending order and then
right click - properties and where it says 'All' type in '1'. This will
return the top value (one record) in the VarNo field.
--
Gina
"access user" wrote:
> I have a query and I wish to restrict the returned values to only those
> where, for a particular field, the value is the highest.
>
> For example, a property can have had a number of rent agreements but, in the Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869 Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
> following example, I don't want ALL the records, just the one where VarNo is
> the highest
>
> PropertyNo TenantNo VarNo
> 1 1 1
> 1 1 2
> 1 2 3
>
> I *only* want the last line not all three lines.
>
> TIA
> James | 
28-Jul-2006, 08:08 AM
|  | Guest | | | | | | | | | | RE: query help - retrieve only those with highest value Thanks - not sure where to put the 1. Bringing up field properties does not
give me any such option.
James
"Gina" wrote:
> In your query you could try putting VarNo field in Descending order and then Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
> right click - properties and where it says 'All' type in '1'. This will
> return the top value (one record) in the VarNo field.
> --
> Gina
>
>
> "access user" wrote:
>
> > I have a query and I wish to restrict the returned values to only those Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
> > where, for a particular field, the value is the highest.
> >
> > For example, a property can have had a number of rent agreements but, in the
> > following example, I don't want ALL the records, just the one where VarNo is
> > the highest
> >
> > PropertyNo TenantNo VarNo
> > 1 1 1
> > 1 1 2
> > 1 2 3
> >
> > I *only* want the last line not all three lines.
> >
> > TIA
> > James | 
28-Jul-2006, 08:08 AM
|  | Guest | | | | | | | | | | RE: query help - retrieve only those with highest value Thanks - I get a syntax error on the following bit:
=(SELECT Max(VarNo) AS MaxVarNo FROM TableName WHERE
missing ) , ] etc...
James Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
"Michael H" wrote:
> Hi.
>
> Assuming the name of your table is "TableName", try this:
>
> SELECT TableName.PropertyNo, TableName.TenantNo, TableName.VarNo
> FROM TableName
> WHERE (TableName.VarNo)=(SELECT Max(VarNo) AS MaxVarNo FROM TableName WHERE Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
> (TableName.ContractEndDate)>=Date());
>
> -Michael
>
>
> "access user" wrote:
>
> > Also, just to clarify this is an *additional* constraint to one I already
> > have in the query. That is, I want only those results where *both* conditions
> > are met.
> > Firstly, where ContractEndDate>=Date()
> > Secondly, where (having met the above condition), VarNo is the highest
> >
> > TIA
> >
> > "access user" wrote:
> >
> > > I have a query and I wish to restrict the returned values to only those
> > > where, for a particular field, the value is the highest.
> > >
> > > For example, a property can have had a number of rent agreements but, in the
> > > following example, I don't want ALL the records, just the one where VarNo is
> > > the highest
> > >
> > > PropertyNo TenantNo VarNo
> > > 1 1 1
> > > 1 1 2
> > > 1 2 3
> > >
> > > I *only* want the last line not all three lines.
> > >
> > > TIA
> > > James | 
28-Jul-2006, 08:08 AM
|  | Guest | | | | | | | | | | RE: query help - retrieve only those with highest value Did you paste the entire bit of SQL I posted? If your SQL ends at the word Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
"WHERE", then you did not. Please ensure thay you copy and paste everything
from the first SELECT statement to the semicolon at the end. I have tested
it and it works just as you had specified it should. Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=9869
If you have done the above and are still having problems, please post the
exact SQL you are using, as something may have gotten changed in the
transition.
-Michael
"access user" wrote:
> Thanks - I get a syntax error on the following bit:
>
> =(SELECT Max(VarNo) AS MaxVarNo FROM TableName WHERE
>
> missing ) , ] etc...
>
> James
>
>
> "Michael H" wrote:
>
> > Hi.
> >
> > Assuming the name of your table is "TableName", try this:
> >
> > SELECT TableName.PropertyNo, TableName.TenantNo, TableName.VarNo
> > FROM TableName
> > WHERE (TableName.VarNo)=(SELECT Max(VarNo) AS MaxVarNo FROM TableName WHERE
> > (TableName.ContractEndDate)>=Date());
> >
> > -Michael
> >
> >
> > "access user" wrote:
> >
> > > Also, just to clarify this is an *additional* constraint to one I already
> > > have in the query. That is, I want only those results where *both* conditions
> > > are met.
> > > Firstly, where ContractEndDate>=Date()
> > > Secondly, where (having met the above condition), VarNo is the highest
> > >
> > > TIA
> > >
> > > "access user" wrote:
> > >
> > > > I have a query and I wish to restrict the returned values to only those
> > > > where, for a particular field, the value is the highest.
> > > >
> > > > For example, a property can have had a number of rent agreements but, in the
> > > > following example, I don't want ALL the records, just the one where VarNo is
> > > > the highest
> > > >
> > > > PropertyNo TenantNo VarNo
> > > > 1 1 1
> > > > 1 1 2
> > > > 1 2 3
> > > >
> > > > I *only* want the last line not all three lines.
> > > >
> > > > TIA
> > > > James | 
Support Us! Become a Promoter! | | Gurfateh ji, you can become a SPN Promoter by Donating as little as $10 each month. With limited resources & high operational costs, your donations make it possible for us to deliver a quality website and spread the teachings of the Sri Guru Granth Sahib Ji, to serve & uplift humanity. Every contribution counts. Donate Generously. Gurfateh! | (View-All)
Members who have read this thread : 0
| | There are no names to display. | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Tools | Search | | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is On | | | | » Gurbani Jukebox | Listen to Gurbani while surfing SPN! | » Recent Discussions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | » Books You Should Read... | | | |