You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

These are examples taken from the mailing list.

How do I write sub-select queries?

// Define the sub query
DBCommand subCmd = db.createCommand();
subCmd.select(...);
// Wrap command for subquery
DBQuery SQ = new DBQuery(subCmd);

// Define the main query
DBCommand cmd = db.createCommand();
cmd.select(..);
cmd.select(SQ.findQueryColumn(...));
cmd.join(..., SQ.findQueryColumn(...));

h3 Self-joins

SampleDB db = new SampleDB();
SampleDB.Departments DEP1 = new Departments(db);
SampleDB.Departments DEP2 = new Departments(db);
// Create the command
DBCommand cmd = db.createCommand();
cmd.select(DEP1.NAME, DEP2.NAME);
cmd.join  (DEP1.DEPARTMENT_ID, DEP2.PARENT_ID);
String sql = cmd.getSelect();
  • No labels