Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to select only the newest request in the database table.
that means i want to select the maximum request ID number and related row values.

I wrote sql query as
SQL
select docName,max(appID) as appID 
from Appointment 
where patID='p00000001' 
group by docName;

An error occured as follow.
An expression of non-boolean type specified in a context where a condition is expected, near ')'.

Any one know a method to solve the problem
Posted
Updated 27-Oct-11 5:25am
v2
Comments
BobJanova 27-Oct-11 11:56am    
That looks like it should work. MAX is a valid aggregation function. Try removing the (redundant, anyway) column alias, maybe that is confusing something.

1 solution

your query looks okay but it will not result the record set of the maximum appid.

try

SQL
select *
from Appointment
where appID = (
select max(appID)
from Appointment
where patID='p00000001')



Also, hope the patID column is varchar ?
 
Share this answer
 
v2
Comments
madhu_ 27-Oct-11 12:34pm    
ya. u r right.
that is the answer i need. thanx
Bala Selvanayagam 28-Oct-11 3:24am    
My pleasure
Amir Mahfoozi 31-Oct-11 9:10am    
+5
Bala Selvanayagam 31-Oct-11 9:33am    
thanks Amir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900