Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL query.

Posted on 2013-05-24
3
Medium Priority
?
305 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
[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
3 Comments
 
LVL 20

Accepted Solution

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

Assisted Solution

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

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

Expert Comment

by:Dale Fye
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 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