brianc / node-sql

SQL generation for node.js
MIT License
1.05k stars 191 forks source link

Top-Level SubQuery support #400

Closed danrzeppa closed 4 years ago

danrzeppa commented 6 years ago

Adds abilty to create a SubQuery without starting with a table. For example:

var sql=require("sql")
var subQuery = sql.subQuery().select(user.id).from(user)
var query=post.select().where(post.user_id.in(subQuery))

In this example, the subQuery could have been defined as user.subQuery().select(), but there are instances when dynamically generating SQL where you may not have the table at the time you want to create the subquery.