R E L A T E D   C O N T E N T
ADVERTISEMENT

Ordering data in Access

Building an order database

PCW Staff, Personal Computer World 04 Aug 2006
ADVERTISEMENT

Q I am building an order database in Access. I have written a query to pull up the most recent order (the one with the highest order number) and then I base a report on the query.

But the query is very specific and has to be rewritten each time. Is there any way to make it more general?
SELECT ORDER.OrderID, ORDER.OrderDate, ORDER.OrderValue
FROM [ORDER]
WHERE (ORDER.OrderID)=6;
Brian Williams

A There are a couple of ways of doing this. For example, you can use a query of the general format:
SELECT ORDER.OrderID, ORDER.OrderDate, ORDER.OrderValue
FROM [ORDER]
WHERE ORDER.OrderID=(SELECT Max(ORDER.OrderID) FROM [ORDER]);

This should work in many different databases engines, although you need to check that they have a function called MAX and, if not, look for a substitute.

However, Access queries also have properties that you can set, one of which is ‘top Value’.

If you set this to the value 1, place the OderID field as the left-most one in the query and sort it in descending order, then the query should return just the top value for OrderID.


All Software Applications
Tags: Databases

Like this story? Spread the news by clicking below:

Post this to Delicious del.icio.us    Post this to Digg Digg this    Post this to reddit reddit!

Permalink for this story
R E A D E R   C O M M E N T S
M A R K E T P L A C E
Get your free demo of Numara Track-It! 8 - the leading help desk solution for IT related issues.
Make presentations, review documents & share your entire desktop. 30-day free trial! (cc required).
Discover how remote support can fuel your IT business in ways you've never thought of before.
Apply ITIL best practices at your service desk while eliminating integration cost. Learn more here.
WAN based, automated, daily vulnerability assessments. Click here to try and request our whitepapers.
Have your product or service listed here >   
Sponsored links
F E A T U R E D   J O B S
Hertfordshire, United Kingdom | Tesco.com
Database Operations Team Leader - Hertfordshire Who's behind the world's most successful online retailer?Just over 10 years ago we started Tesco.com (aka Dotcom). Today, we've an incredible 750,000 active customers and sales at just under £1 ... more >
London, United Kingdom | BP
Business Analyst - £ Competitive - London About BP Our business is the exploration, production, refining, trading and distribution of energy. This is what we do, and we do it on a truly global scale. ... more >
United Kingdom | Ofgem
IT Network and Security Engineer £40,000 per annum The Office of Gas and Electricity Markets (Ofgem) is the regulator for Britain's gas and electricity industries. Our role is to protect consumers and enable them to ... more >
Hertfordshire, United Kingdom | Tesco.com
Senior Business Analyst - Hertfordshire Who's behind the world's most successful online retailer? Just over 10 years ago we started Tesco.com (aka Dotcom). Today, we've an incredible 750,000 active customers and sales at just under ... more >
More job opportunities