|
Question : How to retrieve data from five different tables in Access database
|
|
Hi Experts, I have five tables in an Access database. All five tables have the same field names. FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive are in Table_One FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive are in Table_Two FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive are in Table_Three FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive are in Table_Four FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive are in Table_Five What is the correct SQL to display my data on my ASP page? I was trying SELECT FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive FROM Table_One JOIN Table_Two JOIN Table_Three JOIN Table_Four JOIN Table_Five WHERE EmpNum1='" & myId &"' but it's not working. Thank you for your help
|
|
Answer : How to retrieve data from five different tables in Access database
|
|
You could take the result of the unions as a query and apply a where clause to the entire result if you need to.
e.g. (lets call this "Query1") SELECT FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive FROM Table_One UNION ALL SELECT FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive FROM Table_Two UNION ALL SELECT FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive FROM Table_Three UNION ALL SELECT FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive FROM Table_Four UNION ALL SELECT FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive FROM Table_Five
... then as another query (say "Query2")... SELECT FieldOne, FieldTwo, FieldThree, FieldFour, FieldFive from Query1 where FieldOne = '" & myId &"'
|
|
|
|