File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1616use Cycle \Database \Query \QueryParameters ;
1717use Cycle \Database \Query \SelectQuery ;
1818
19+ /**
20+ * This fragment is used to inject a whole select statement into
21+ * FROM and SELECT parts of the query.
22+ *
23+ * Examples:
24+ *
25+ * ```
26+ * $subQuery = new SubQuery($queryBuilder->select()->from(['users']),'u');
27+ * $query = $queryBuilder->select()->from($subQuery);
28+ * ```
29+ *
30+ * Will provide SQL like this: SELECT * FROM (SELECT * FROM users) AS u
31+ *
32+ * ```
33+ * $subQuery = new SubQuery($queryBuilder->select()->from(['users']),'u');
34+ * $query = $queryBuilder->select($subQuery)->from(['employee']);
35+ * ```
36+ *
37+ * Will provide SQL like this: SELECT *, (SELECT * FROM users) AS u FROM employee
38+ */
1939class SubQuery implements FragmentInterface
2040{
2141 private SelectQuery $ query ;
Original file line number Diff line number Diff line change 1313
1414use Cycle \Database \Injection \Expression ;
1515use Cycle \Database \Injection \Fragment ;
16+ use Cycle \Database \Injection \SubQuery ;
1617use Cycle \Database \Query \Traits \WhereJsonTrait ;
1718use Cycle \Database \Driver \CompilerInterface ;
1819use Cycle \Database \Injection \FragmentInterface ;
@@ -84,6 +85,16 @@ public function distinct(bool|string|FragmentInterface $distinct = true): self
8485 /**
8586 * Set table names SELECT query should be performed for. Table names can be provided with
8687 * specified alias (AS construction).
88+ * Also, it is possible to use SubQuery.
89+ *
90+ * Following example will provide SQL like this: SELECT * FROM (SELECT * FROM users) AS u
91+ *
92+ * ```
93+ * $subQuery = new SubQuery($queryBuilder->select()->from(['users']),'u');
94+ * $query = $queryBuilder->select()->from($subQuery);
95+ * ```
96+ *
97+ * @see SubQuery
8798 */
8899 public function from (mixed $ tables ): self
89100 {
You can’t perform that action at this time.
0 commit comments