Ask Your Question

Base: query a query?

asked 2015-06-17 11:54:46 +0200

UserError gravatar image

updated 2015-08-25 17:55:17 +0200

Alex Kemp gravatar image

Hello, I'm running Base Version on Linux Mint 17. I'm trying to rebuild/replicate a small Access db I made a while ago. In Access I could query a query, but don't seem able to do this - getting a "The data content could not be loaded."

error SQL Status: 37000 Error code: -70

"The SQL command leading to this error is: SELECT "ID2" AS "ID2", "FirstName" AS "FirstName", "LastName" AS "LastName", etc etc"

I've tried to research this info but get out of my depth very quickly as it's mostly about servers & SQL etc. I've tried altering elements that look like they might be the problem (eg ORDER), but no joy either. I've tried running the underlying query & leaving it open. Nope.

I've fallen at the first hurdle with Base, so any help would be appreciated. Many thanks

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-06-18 04:37:12 +0200

doug gravatar image

You can accomplish your objective in either of two ways.

1) Save the queries as 'views'.

Do this by browsing to Tables and then clicking Create View.

image description

You then will see the query builder. This option is much closer to the functionality in the other leading desktop database system. I think the difference is that the work of the querying is done entirely within the database server this way, and some back-ends (like MySQL) have limitations on the kinds of queries that can be saved as a View (no internal subqueries -- but you can refer to other views).

That probably will be your choice, and will be familiar.

2) Write your stacked queries as a single query with a subquery.

To do this, under the Query tab you will need to select Create Query in SQL View. Then, you would re-write your two queries as one, as follows:

SELECT `sub`.`lastname`, `sub`.`firstname`
  SELECT `t1`.`lastname`, `t1`.`firstname`
  FROM `t1` AS `t1`
) AS `sub`

Just go into your first query in SQL View, copy the SQL then go into your second query, and where it would be FROM t2, make a parenthesis and inside that add the first query. Then name the subquery.

FWIW, if you do option two, avoid reopening in the Query Builder. Just use SQL View as the Query Builder is buggy and sometimes renders good queries unusable.

(if this answered your question, accept the answer by clicking the check mark (image description) to the left)

edit flag offensive delete link more


Thanks for this. I had a lot of trouble with Base so I'm trying out SQLite/Kexi to see if that will do what I need & SQLite/Spatialite can be used in my GIS

UserError gravatar imageUserError ( 2016-04-29 10:54:12 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-06-17 11:54:46 +0200

Seen: 1,312 times

Last updated: Jun 18 '15