I'm just getting my feet wet in mySQL (actually, I just got thrown in over my head!), so I apologize for not being able to define my question in a more succinct manner. I need to construct a SELECT statement that pulls data from two tables (A & B, neither of them are my design). In addition to columns "InvoiceAmt" and "Salesperson" from table A, the returned data needs to have three columns: "Country", "State/Province", and "City".
Table A has sales data, including columns named "InvoiceAmt", "Salesperson", and "RegionID".
Table B has region information, with columns structured as follows:
"RegionID": unique identifier index number
"RegionDescription": A country, state, OR city name
"ComesUnder": Contains RegionID this RegionID comes under (like Texas comes under USA), or 0 if none
"ComesAbove": comma-delimited list of RegionID's this RegionID comes above (like Texas comes above Dallas and San Antonio), or blank if none. Data from Table B might look like:
1 | USA | 0 | 2
2 | Texas | 1 | 3,4
3 | Dallas | 2 |
4 | San Antonio | 2 |
I honestly don't know where to begin. Can anyone give me pointers on how to structure a query that will populate as many of the three columns (Country, State, City) as possible for each sales record? For example, if a sales record has the RegionID for Texas, the returned result for that record would include Country = "USA", State = "Texas", and City = (blank).
Thank you!
VBAjedi
Table A has sales data, including columns named "InvoiceAmt", "Salesperson", and "RegionID".
Table B has region information, with columns structured as follows:
"RegionID": unique identifier index number
"RegionDescription": A country, state, OR city name
"ComesUnder": Contains RegionID this RegionID comes under (like Texas comes under USA), or 0 if none
"ComesAbove": comma-delimited list of RegionID's this RegionID comes above (like Texas comes above Dallas and San Antonio), or blank if none. Data from Table B might look like:
1 | USA | 0 | 2
2 | Texas | 1 | 3,4
3 | Dallas | 2 |
4 | San Antonio | 2 |
I honestly don't know where to begin. Can anyone give me pointers on how to structure a query that will populate as many of the three columns (Country, State, City) as possible for each sales record? For example, if a sales record has the RegionID for Texas, the returned result for that record would include Country = "USA", State = "Texas", and City = (blank).
Thank you!
VBAjedi