How can I create a Query from a table with multiple order types and reference numbers

tesleen2025

New Member
Joined
Nov 23, 2016
Messages
13
Hi,
I have a table that I access through ODBC. I can not edit or modify this table in any way. This table has multiple order types. Some order types have a reference id back to another order type. I would like to get the actual order number for those reference id's. I hope this makes sense. Here is a sample of what I want to do.

I'm not sure what I need to do to get the results I'm looking for.


Current Table
TypeOrderIDOrderNumberAmountRefOrderID
Invoice123456401-1234$$$89645
Invoice123789401-1235$$$87658
Repair89645401-6785$$$
Repair87658401-6786$$$
Warranty646803401-0033$$$89645
Warranty646899401-0034$$$87658
What I want my filtered Query to look like
TypeOrderIDOrderNumberAmountRefOrderIDRefOrderNumber
Warranty646803401-0033$$$89645401-6785
Warranty646899401-0034$$$87658401-6786

<tbody>
</tbody>


Respectfully,
TSmith
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The left 5 fields look easy enough - the query would filter on Type (which probably isn't the real name of the field since that's a reserved word in Access and shouldn't be used as such). As for the rightmost field, you need to include and join the other table, but I cannot advise what fields you'd join on as you provided no information about it. Perhaps it is an order reference ID field that exists in both tables.
Some order types have a reference id back to another order type
doesn't provide much info. Your results may not exactly resemble your example because of that join, so additional joins or criteria or a different join may be required. I presume you're OK with linking the ODBC tables to your database in the first place.
 
Last edited:
Upvote 0
A self-join might work:
Code:
SELECT 
	t1.[Type], 
	t1.OrderID, 
	t1.OrderNumber, 
	t1.Amount, 
	t1.RefOrderID, 
	t2.OrderNumber as RefOrderNumber
FROM 
	MyTable AS t1
	 LEFT JOIN
	 MyTable AS t2
	 ON t1.RefOrderID = t2.OrderID
 
Upvote 0
Xenou, I'm not familiar with script in Access however I was able to bring the table in a second time and create a self-join and it worked. I would not have thought to do that without your suggestion. Thank you!
 
Upvote 0

Forum statistics

Threads
1,221,614
Messages
6,160,839
Members
451,673
Latest member
wella86

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top