How can I query a database to extract data from multiple tables?

8 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
I am using the Database Toolbox to connect to an Access database that has multiple tables. I would like to query the tables to retrieve information from the Database.

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
The key to retrieving information from a database is the query that is passed to the driver to retrieve that information. The code below shows an example of connecting to a database, and retrieving data from multiple tables based on some criteria.
query = 'SELECT ALL Table1.Name, Table1.Number FROM Table2, Table1 WHERE Table1.Number = Table2.Number AND Table1.Name = Table2.Name';
conn = database('Example','','');
cursor = exec(conn,query);
results = fetch(cursor);
results.data
Note that you will need to download the attached MDB-file and create a new data source in Access. To set up the data source, follow the steps below:
1) Download the attached MDB file and save it as Example.mdb
2) In your system's Control Panel, open up the Administrative Tools dialog
3) Select the Data Source (ODBC) tool
4) Add a new datasource, called Example, by selecting the Data Source to be the file downloaded in step 1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by