AllExperts > Using MS Access 
Search      
Using MS Access
Volunteer
Answers to thousands of questions
 Home · More Using MS Access Questions · Answer Library  · Encyclopedia ·
More Using MS Access Answers
Question Library

Ask a question about Using MS Access
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Geoff
Expertise
I specialise in database analysis and design, SQL and database queries using QBE and VBA. In my work, I use MS Access together with MS SQL Server as ETL (Extraction - Transformation - Loading) tools for migrating data between business ERP systems and data stores. My forte is building bespoke functions and applications.


See my website for example apps and downloads


Experience
I am a chartered engineer with 30 years of engineering and business experience, member of the BCS and have been working specifically in database applications, including SQL Server (v7/8/2000) for the last 9 or so years. I previously taught a course in Database Analysis and Design, but am now a freelance consultant and systems analyst.

Commercial database design and development work undertaken.

 
   

You are here:  Experts > Computing/Technology > Business Software > Using MS Access > MS Access Help

Using MS Access - MS Access Help


Expert: Geoff - 2/20/2005

Question
Hello, was wondering if you could help, The problem is very simple, I have a Simple table that I am using, one of the fields is called Indicator, there are only two possible values that are the Number 1 and Number 2. What I want to do is run a query (or something) that returns only the first record where the value in the Indicator field = 1, then all of the remaining records regardless of the value of field Indicator.
Thank you very much for your help.


Answer
Hi Jim

The query below should do what you want: you will need to substitute in the values where I have put in dummy elements.

SELECT TOP 1 Xx, Yy, Zz
FROM tblYourTable
WHERE [Indicator]=1
ORDER BY Xx, Yy, Zz

UNION

SELECT Xx, Yy, Zz
FROM tblYourTable
WHERE [Xx] Not In (
  SELECT TOP 1 Xx, Yy, Zz
  FROM tblYourTable
  WHERE [Indicator]=1
  ORDER BY Xx, Yy, Zz
)
ORDER BY Xx, Yy, Zz

Basically what we have is a UNION query, which is the joining of two similar queries. The top query returns the first record with an [Indicator] = 1 to your specified sort order (Xx, Yy, Zz)

The lower query returns all other records by you sort criteria, but excludes the record from the top query. Please note that this exclusion is based on the column [Xx], which I have assumed to be Primary or Unique Key.

If you have any problems getting this to work please revert with some sample data ( say 10 records).

With kind regards

Geoff Johns :-)

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.