Select All from Sub-query

Hi, I'm trying to figure out if it's possible for me to select all the columns from a sub-query. I imagine if it were possible it'd be something like this:
const subQuery = db().select({ ... }).from(...).as("subquery");

const query = db()
.select({ ...subQuery })
.from(subQuery);
const subQuery = db().select({ ... }).from(...).as("subquery");

const query = db()
.select({ ...subQuery })
.from(subQuery);
Do I have to name all the columns?
4 Replies
Mario564
Mario5643mo ago
You can just do .select() and that should get you every column defined in subQuery
Jaden
JadenOP3mo ago
@Mario564 My bad I didn't explain correctly what I'm trying to do. The problem I have with that solution is I want to add other columns to the select but get all the columns from the sub-query as well. For instance:
const subQuery = db().select({ ... }).from(...).as("subquery");

const query = db()
.select({
a: ...,
b: ...,
...subQuery
})
.from(subQuery);
const subQuery = db().select({ ... }).from(...).as("subquery");

const query = db()
.select({
a: ...,
b: ...,
...subQuery
})
.from(subQuery);
I thought there might be a function like .all() on the sub-query that would let me do this, but I can't seem to find an easy solution like that.
Mario564
Mario5643mo ago
Oh, I see what you mean now. We only have a function gets all table columns but not for subqueries or views.
copypaper
copypaper2w ago
did you ever figure this out?
Want results from more Discord servers?
Add your server