Access Union Query

Hello,

The following screen shot is my query.

access query
Usually, only one set of criteria is true and everything runs fine, but now I'm running into where both criteria's are true.  When both are true, the result is:

query result
When this happens, I want it to only return the first row.

Thank you,
Joel
Genius123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
That is not a Union Query, that is an INNER JOIN.

You could try:

SELECT Top 1 ...
0
Pawan KumarDatabase ExpertCommented:
So if you have multiple Ids the TOP 1 will not work... basically for each ID,POS_NR....we need first record.
We can do something like below.

SELECT ID,POS_NR, MAX(Shape) AS Shape , MAX(Aris) AS Aris , MAX(BOM_PRODI) BOM_PRODI
FROM
(
   /* Your EXISTING Query*/
) AS R
GROUP BY ID,POS_NR
0
Dale FyeOwner, Developing Solutions LLCCommented:
Except

Max(Shape), Max(Aris), Max(BOM_Prodi)

does not guarantee that you will get the Shape, Aris, and BOM_Prodi from the same record.  In this example, it would return:

Shape #1                999901          Aris Edges 2/4

Where Shape #1 comes from first record, and 999901 comes from the 2nd.

Since the query criteria specifices the ID and POS_NR, there is no need to group by those columns.  However, you would need to figure out what your criteria is for selecting the "Top" row, and add an Order By clause to the query so that the row you want would sort to the top.  It might look like:

ORDER BY IIF([BOM_PRODUKT] > 8000 AND [BOM_PRODUKT] < 8200, 1, 2)
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Pawan KumarDatabase ExpertCommented:
I think we some unique ID or Date column to fetch the first record.
0
Gustav BrockCIOCommented:
Add a second criteria in column BOM_Produkt, on the line labeled "or:"

<=8000 Or >=8200

Open in new window

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
Since the OP never responded back, there is no way to determine which of the provided solutions would have met the desired outcome.  

Dale Fye and Gustav Brock both provided solutions which might meet the OPs needs.

I recommend either splitting the points of deleting the question for not enough information.
0
Gustav BrockCIOCommented:
Solution provided.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.