Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL query.

Posted on 2013-05-24
3
Medium Priority
?
311 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 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 49

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

824 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