Brackets within a SQL query
Mostra commenti meno recenti
Hi everybody,
I'm using the fetch function (results = fetch(conn,sqlquery)) to get data from a database into MATLAB. In the database there are many tables and I want to create a query that enables me to get data from different tables (in this case the first 5 entries of every table). Doing so I tried those queries to get data from a single table:
sqlquery1 = ['SELECT a, b FROM table1 LIMIT 5];
sqlquery2 = ['SELECT a, b FROM table2 LIMIT 5];
Due to the fact that I have to get data from 30 and more tables I don't want to send a single query each time. So I tried:
sqlquery = ['(SELECT a, b FROM table1 LIMIT 5) UNION (SELECT a, b FROM table2 LIMIT 5)'];
but it wouldn't work.
Due to this I also tried:
sqlquery1 = ['(SELECT a, b FROM table1 LIMIT 5)'];
which wouldn't work either.
Do you have any ideas why MATLAB doesn't accept the brackets?
Is there another way to solve the problem?
Cheers,
Christoph
1 Commento
Guillaume
il 20 Lug 2016
I assume you're talking about the curved brackets () around the SELECT query.
I was a bit confused at first because of the square brackets [] in your post that serve absolutely no purpose.
string = ['xxxx']
is exactly the same as
string = 'xxxx'
Risposte (1)
the cyclist
il 20 Lug 2016
0 voti
I successfully returned results from a query of this format (against a Postgres 9.5 database). I have two suggestions:
- Issue that same query directly against the database (not via MATLAB) to see if you get any kind of error.
- Post the full error message you are getting, so we can take a more detailed look
Categorie
Scopri di più su Database Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!