Solved

SQL query.

Posted on 2013-05-24
3
289 Views
Last Modified: 2013-05-24
Hi Experts,

I want to select all customer names from a table that share the highest ID. The following sql shows what I want to do but does not work.

SELECT CustomerName FROM tblCustomers WHERE ID = MAX(ID)
0
Comment
Question by:DColin
3 Comments
 
LVL 20

Accepted Solution

by:
dsacker earned 300 total points
ID: 39195355
SELECT CustomerName FROM tblCustomers
WHERE ID = (SELECT MAX(ID) FROM tblCustomers)
0
 
LVL 12

Assisted Solution

by:pdebaets
pdebaets earned 200 total points
ID: 39195356
Try this

Select CustomerName from tblCustomers where ID in (Select Max([ID]) from tblCustomers);
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39195381
I cannot imagine why this would bring back more than one record, as you generally don't repeat ID values, and:

SELECT Max([ID]) from tblCustomers

would only return a single ID value.

Can you describe (in words, not SQL) what it is you really want to accomplish?  

You may have to provide  a little more detail about your table structure.  If you could provide a couple of sample records (sanitized to avoid revealing personal, financial, or proprietary information) , that would be even better.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

685 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