Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

max function

Status
Not open for further replies.

johk02

Programmer
Aug 20, 2003
169
AU
Hi,
Are there anyway of getting more columns from a Max query?? I am using query
SELECT MAX(MemberID) AS InitNo
FROM tbl_member

but would like to retrieve more info from that query like

SELECT MAX(MemberID) AS InitNo, MemberNoInitials, ReferredBy
FROM tbl_member

Any suggestions

Thanks
jonas
 
SELECT MAX(MemberID) AS InitNo, MemberNoInitials, ReferredBy
FROM tbl_member
GROUP BY MemberNoInitials, ReferredBy
 

Thanks mate
It seems to do the trick. I added Order by DESC as well.

Thanks
 
Depending of your real issue you may try this:
SELECT * FROM tbl_member
WHERE MemberID=(SELECT MAX(MemberID) FROM tbl_member)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
johk02,

every field that you include in the select statement that isn't an aggregate (like SUM, AVG, COUNT) you have to add to the Group By statement.

For instance, if you needed to add AField to this query, you would also need to add that field to the Group By clause:
Code:
SELECT MAX(MemberID) AS InitNo, MemberNoInitials, ReferredBy, AField
FROM tbl_member
GROUP BY MemberNoInitials, ReferredBy, AField



Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top