With your code query2 ends up being
SELECT * FROM ( 'SELECT * FROM table1 WHERE name LIKE 'a_'' ) WHERE age = '55'
If you change
String query2 = "SELECT * FROM ( '" + query1 + "' ) WHERE age = '55'";
to
String query2 = "SELECT * FROM ( " + query1 + " ) WHERE age = '55'";
(note the deleted ') it ends up:
SELECT * FROM ( SELECT * FROM table1 WHERE name LIKE 'a_' ) WHERE age = '55'
which should be correct SQLite syntax.
I suspect that error on missing database is coming from a "confused" SQLite and could be solved by fixing the syntax. Otherwise please provide the result of this change, preferrably in the shape of a MCVE.
I do not get the purpose of that query by the way, it seems somewhat roundabout...
query1. You probably need to first execute that query and then use the (hopefully single-word) result in the concatenation you seem to attempt in the second query.query2ends up beingSELECT * FROM ( 'SELECT * FROM table1 WHERE name LIKE 'a_'' ) WHERE age = '55'doesn't it? The'a_''looks fishy.