• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

SQL query.

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
DColin
Asked:
DColin
2 Solutions
 
dsackerContract ERP Admin/ConsultantCommented:
SELECT CustomerName FROM tblCustomers
WHERE ID = (SELECT MAX(ID) FROM tblCustomers)
0
 
pdebaetsCommented:
Try this

Select CustomerName from tblCustomers where ID in (Select Max([ID]) from tblCustomers);
0
 
Dale FyeCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now