Brackets within a SQL query
显示 更早的评论
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 个评论
Guillaume
2016-7-20
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'
回答(1 个)
the cyclist
2016-7-20
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Database Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!