You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2015/10/06 05:15:25 UTC
svn commit: r1706948 -
/db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml
Author: tfischer
Date: Tue Oct 6 03:15:25 2015
New Revision: 1706948
URL: http://svn.apache.org/viewvc?rev=1706948&view=rev
Log:
TORQUE-290: documentation
Modified:
db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml
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 (original)
+++ 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);
</source>
+
+ <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>
+
+<source>
+SELECT author.author_id, author.name FROM author WHERE (SELECT COUNT(*) FROM book WHERE (book.author_id=author.author_id AND book.title=?))=?
+</source>
+
+ <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>
+
+<source>
+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);
+</source>
+
+ <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>
<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