How can I query a database to extract data from multiple tables?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
Réponse acceptée
MathWorks Support Team
le 27 Juin 2009
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Database Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!