Microsoft Excel Tutorial: How to Execute a Database Query

Kantus
You can execute a Microsoft Access database query from within a Microsoft Excel worksheet. Basically, if you have a Microsoft Access database with a table and/or a query saved, you can execute a query against that table or execute the saved query and display the results into the cells of your Excel worksheet.

1. Create New Excel File

Create a new Microsoft Excel workbook with a blank worksheet to use for this Excel database query tutorial. You could also follow along for this tutorial using a pre-existing workbook.

2. Click Data -> Import External Data -> New Database Query

You will be presented with a window called "Choose Data Source". This window gives you the option to select the data source you want to use for the Excel database query. Under the "Database" tab, the provided options are "", "dBASE Files", "Excel Files", "MS Access Database", and so on, depending on what software you have installed on the machine.

3. Select "MS Access Database"

We want to use the Access Database so select that option and click OK. You will see a window in the middle of the screen that says "Connecting to data source..." and another window titled "Select Database".

4. Locate a Database

In the "Select Database" window, locate a .mdb file that is a Microsoft Access database. For this example, I will use an Access database created from a previous tutorial called "MyFirstAccessDB". Select your database and click OK. Another window called "Query Wizard - Choose Columns".

5. Select Tables or Fields

In this window, there are 3 main sections. "Available tables and columns" shows you the tables and queries that exist in that database, "Columns in your query" shows you the columns that are currently being used in your query, and "Preview of data in selected column" allows you to select any column from the "Column in your query" list and it will show you a Preview of the results if you click on the "Preview" button on the lower left corner. For my example, there is already a saved query from the previous example called "People Query". I will simply click on it and then click the ">" to bring all the fields over to the other section and then click Next.

6. Filter Data

The wizard will now ask you if you want to filter the data, and if yes, what criteria you want to filter by. This is similar to the "Where" statement in SQL. I will skip this by clicking Next.

7. Sort Order

You can choose to select the sorting options for the available fields in this step of the wizard for creating an Excel database query, but for this example, you can click Next.

8. Select "Return Data to Microsoft Office Excel"

Finally, select the return data to Excel option in the final step and click Finish. You will now be prompted with the "Import Data" window that asks you where you want to place the data. Click on any cell in the worksheet and click OK. You will now see the data from the query (including column headers), into the cells of the worksheet!

Published by Kantus

I love writing short stories and humor articles, but tend to stick with topics that are discoverable by search engines and capable of spreading virally.  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.