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.


[TABLE="width: 630"]
<tbody>[TR]
[TD="colspan: 2"]Current Table[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Type[/TD]
[TD]OrderID[/TD]
[TD]OrderNumber[/TD]
[TD]Amount[/TD]
[TD]RefOrderID[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Invoice[/TD]
[TD]123456[/TD]
[TD]401-1234[/TD]
[TD]$$$[/TD]
[TD]89645[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Invoice[/TD]
[TD]123789[/TD]
[TD]401-1235[/TD]
[TD]$$$[/TD]
[TD]87658[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Repair[/TD]
[TD]89645[/TD]
[TD]401-6785[/TD]
[TD]$$$[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Repair[/TD]
[TD]87658[/TD]
[TD]401-6786[/TD]
[TD]$$$[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Warranty[/TD]
[TD]646803[/TD]
[TD]401-0033[/TD]
[TD]$$$[/TD]
[TD]89645[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Warranty[/TD]
[TD]646899[/TD]
[TD]401-0034[/TD]
[TD]$$$[/TD]
[TD]87658[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3"]What I want my filtered Query to look like[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Type[/TD]
[TD]OrderID[/TD]
[TD]OrderNumber[/TD]
[TD]Amount[/TD]
[TD]RefOrderID[/TD]
[TD]RefOrderNumber[/TD]
[/TR]
[TR]
[TD]Warranty[/TD]
[TD]646803[/TD]
[TD]401-0033[/TD]
[TD]$$$[/TD]
[TD]89645[/TD]
[TD]401-6785[/TD]
[/TR]
[TR]
[TD]Warranty[/TD]
[TD]646899[/TD]
[TD]401-0034[/TD]
[TD]$$$[/TD]
[TD]87658[/TD]
[TD]401-6786[/TD]
[/TR]
</tbody>[/TABLE]


Respectfully,
TSmith
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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