Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

These are examples taken from the mailing list.

...

Table of Contents

Sub-select

...

Code Block
java
java
       // 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(...));

Self-joins

Code Block
java
java
SampleDB db = new SampleDB();
SampleDB.Departments DEP1 = new Departments(db);
SampleDB.Departments DEP2 = new Departments(db);
// Create the command
DBCommand cmd = db.joincreateCommand();
cmd.select(DEP1..NAME, DEP2.NAME);
cmd.join  (DEP1.DEPARTMENT_ID, DEP2.PARENT_ID);
String sql = cmd.getSelect();

Union

Code Block
java
java

DBCommandExpr union = cmd1.union(cmd2);
String sql = union.getSelect(SQ.findQueryColumn(...));