Return-Path: X-Original-To: apmail-db-torque-dev-archive@www.apache.org Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 54CFF18CBE for ; Tue, 6 Oct 2015 03:15:36 +0000 (UTC) Received: (qmail 25178 invoked by uid 500); 6 Oct 2015 03:15:36 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 25139 invoked by uid 500); 6 Oct 2015 03:15:36 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 25128 invoked by uid 500); 6 Oct 2015 03:15:36 -0000 Received: (qmail 25123 invoked by uid 99); 6 Oct 2015 03:15:36 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Oct 2015 03:15:36 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 9B284180A54 for ; Tue, 6 Oct 2015 03:15:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.009 X-Spam-Level: X-Spam-Status: No, score=-0.009 tagged_above=-999 required=6.31 tests=[T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id JJ-Kxy4bUiYr for ; Tue, 6 Oct 2015 03:15:28 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id 58C4C21231 for ; Tue, 6 Oct 2015 03:15:27 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4795BE045B for ; Tue, 6 Oct 2015 03:15:26 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id AA33B3A0922 for ; Tue, 6 Oct 2015 03:15:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: torque-commits@db.apache.org From: tfischer@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151006031525.AA33B3A0922@svn01-us-west.apache.org> 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); + + +

+ 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 +

+ + +SELECT author.author_id, author.name FROM author WHERE (SELECT COUNT(*) FROM book WHERE (book.author_id=author.author_id AND book.title=?))=? + + +

+ 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 +

+ + +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); + + +

+ 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 + subquery.addFrom(...). +

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