db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1706948 - /db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml
Date Tue, 06 Oct 2015 03:15:25 GMT
Author: tfischer
Date: Tue Oct  6 03:15:25 2015
New Revision: 1706948

URL: http://svn.apache.org/viewvc?rev=1706948&view=rev
TORQUE-290: documentation


Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml?rev=1706948&r1=1706947&r2=1706948&view=diff
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml
Tue Oct  6 03:15:25 2015
@@ -835,6 +835,43 @@ criteria.where(AuthorPeer.AUTHOR_ID, sub
 List authors = AuthorPeer.doSelect(criteria);
+    <subsection name="Referencing the outer select from subselects">
+      <p>
+        In subselects, columns from the outer query can be referenced.
+        For example, for selecting the authors which have written exactly one book
+        with a given title, one could use the SQL statement
+      </p>
+SELECT author.author_id, author.name FROM author WHERE (SELECT COUNT(*) FROM book WHERE (book.author_id=author.author_id
AND book.title=?))=?
+      <p>
+        Note that in the subselect, a column from the outer select (author.author_id)
+        is referenced but the table author does not appear in the FROM clause
+        of the subselect (so that the database knows the outer select is referenced
+        instead of creating an inner join in the subselect).
+        As Torque will automatically remove tables from the outer select
+        from the FrOM clause of the inner select, the above query can be crated by
+      </p>
+Criteria subquery = new Criteria();
+subquery.where(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);
+subquery.and(BookPeer.TITLE, "SomeTitle");
+subquery.addSelectColumn(new Count("*"));
+Criteria criteria = new Criteria();
+criteria.where(subquery, 1);
+      <p>
+        If the automatical removal of tables from the FROM clause is not desired,
+        the FROM clause in the subselect can be specified manually using the method
+        <code>subquery.addFrom(...)</code>.
+      </p>
+    </subsection>
   <section name="Subselects in the FROM clause">

To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org

View raw message