1
0
mirror of synced 2025-01-18 06:21:40 +03:00

code type is sql

This commit is contained in:
jackbravo 2007-09-06 16:31:07 +00:00
parent 8c0ec95802
commit 722f7903fd
10 changed files with 44 additions and 44 deletions

View File

@ -4,7 +4,7 @@
A string literal is enclosed in single quotes; for example: 'literal'. A string literal that includes a single quote is represented by two single quotes; for example: 'literal''s'. A string literal is enclosed in single quotes; for example: 'literal'. A string literal that includes a single quote is represented by two single quotes; for example: 'literal''s'.
<code> <code type="sql">
FROM User WHERE User.name = 'Vincent' FROM User WHERE User.name = 'Vincent'
</code> </code>
@ -12,7 +12,7 @@ FROM User WHERE User.name = 'Vincent'
Integer literals support the use of PHP integer literal syntax. Integer literals support the use of PHP integer literal syntax.
<code> <code type="sql">
FROM User WHERE User.id = 4 FROM User WHERE User.id = 4
</code> </code>
@ -20,7 +20,7 @@ FROM User WHERE User.id = 4
Float literals support the use of PHP float literal syntax. Float literals support the use of PHP float literal syntax.
<code> <code type="sql">
FROM Account WHERE Account.amount = 432.123 FROM Account WHERE Account.amount = 432.123
</code> </code>
@ -28,7 +28,7 @@ FROM Account WHERE Account.amount = 432.123
The boolean literals are true and false. The boolean literals are true and false.
<code> <code type="sql">
FROM User WHERE User.admin = true FROM User WHERE User.admin = true
FROM Session WHERE Session.is_authed = false FROM Session WHERE Session.is_authed = false
@ -38,7 +38,7 @@ FROM Session WHERE Session.is_authed = false
The enumerated values work in the same way as string literals. The enumerated values work in the same way as string literals.
<code> <code type="sql">
FROM User WHERE User.type = 'admin' FROM User WHERE User.type = 'admin'
</code> </code>
@ -96,7 +96,7 @@ An IN conditional expression returns true if the //operand// is found from resul
When //value list// is being used there must be at least one element in that list. When //value list// is being used there must be at least one element in that list.
<code> <code type="sql">
FROM C1 WHERE C1.col1 IN (FROM C2(col1)); FROM C1 WHERE C1.col1 IN (FROM C2(col1));
FROM User WHERE User.id IN (1,3,4,5) FROM User WHERE User.id IN (1,3,4,5)
@ -104,7 +104,7 @@ FROM User WHERE User.id IN (1,3,4,5)
The keyword IN is an alias for = ANY. Thus, these two statements are equal: The keyword IN is an alias for = ANY. Thus, these two statements are equal:
<code> <code type="sql">
FROM C1 WHERE C1.col1 = ANY (FROM C2(col1)); FROM C1 WHERE C1.col1 = ANY (FROM C2(col1));
FROM C1 WHERE C1.col1 IN (FROM C2(col1)); FROM C1 WHERE C1.col1 IN (FROM C2(col1));
</code> </code>
@ -157,7 +157,7 @@ The NOT EXISTS operator returns TRUE if the subquery returns 0 rows and FALSE ot
Finding all articles which have readers: Finding all articles which have readers:
<code> <code type="sql">
FROM Article a FROM Article a
WHERE EXISTS (SELECT r.id FROM ReaderLog r WHERE EXISTS (SELECT r.id FROM ReaderLog r
WHERE r.article_id = a.id) WHERE r.article_id = a.id)
@ -165,7 +165,7 @@ FROM Article a
Finding all articles which don't have readers: Finding all articles which don't have readers:
<code> <code type="sql">
FROM Article a FROM Article a
WHERE NOT EXISTS (SELECT r.id FROM ReaderLog r WHERE NOT EXISTS (SELECT r.id FROM ReaderLog r
WHERE r.article_id = a.id) WHERE r.article_id = a.id)
@ -184,19 +184,19 @@ operand comparison_operator ALL (subquery)
An ALL conditional expression returns true if the comparison operation is true for all values in the result of the subquery or the result of the subquery is empty. An ALL conditional expression is false if the result of the comparison is false for at least one row, and is unknown if neither true nor false. An ALL conditional expression returns true if the comparison operation is true for all values in the result of the subquery or the result of the subquery is empty. An ALL conditional expression is false if the result of the comparison is false for at least one row, and is unknown if neither true nor false.
<code> <code type="sql">
FROM C WHERE C.col1 < ALL (FROM C2(col1)) FROM C WHERE C.col1 < ALL (FROM C2(col1))
</code> </code>
An ANY conditional expression returns true if the comparison operation is true for some value in the result of the subquery. An ANY conditional expression is false if the result of the subquery is empty or if the comparison operation is false for every value in the result of the subquery, and is unknown if neither true nor false. An ANY conditional expression returns true if the comparison operation is true for some value in the result of the subquery. An ANY conditional expression is false if the result of the subquery is empty or if the comparison operation is false for every value in the result of the subquery, and is unknown if neither true nor false.
<code> <code type="sql">
FROM C WHERE C.col1 > ANY (FROM C2(col1)) FROM C WHERE C.col1 > ANY (FROM C2(col1))
</code> </code>
The keyword SOME is an alias for ANY. The keyword SOME is an alias for ANY.
<code> <code type="sql">
FROM C WHERE C.col1 > SOME (FROM C2(col1)) FROM C WHERE C.col1 > SOME (FROM C2(col1))
</code> </code>
@ -204,7 +204,7 @@ The comparison operators that can be used with ALL or ANY conditional expression
NOT IN is an alias for <> ALL. Thus, these two statements are equal: NOT IN is an alias for <> ALL. Thus, these two statements are equal:
<code> <code type="sql">
FROM C WHERE C.col1 <> ALL (FROM C2(col1)); FROM C WHERE C.col1 <> ALL (FROM C2(col1));
FROM C WHERE C.col1 NOT IN (FROM C2(col1)); FROM C WHERE C.col1 NOT IN (FROM C2(col1));
</code> </code>

View File

@ -1,4 +1,4 @@
<code> <code type="sql">
DELETE FROM <component_name> DELETE FROM <component_name>
[WHERE <where_condition>] [WHERE <where_condition>]
[ORDER BY ...] [ORDER BY ...]

View File

@ -1,13 +1,13 @@
Syntax: Syntax:
<code> <code type="sql">
FROM <component_reference> [[LEFT | INNER] JOIN <component_reference>] ... FROM <component_reference> [[LEFT | INNER] JOIN <component_reference>] ...
</code> </code>
The {{FROM}} clause indicates the component or components from which to retrieve records. If you name more than one component, you are performing a join. For each table specified, you can optionally specify an alias. The {{FROM}} clause indicates the component or components from which to retrieve records. If you name more than one component, you are performing a join. For each table specified, you can optionally specify an alias.
Consider the following DQL query: Consider the following DQL query:
<code> <code type="sql">
FROM User u FROM User u
</code> </code>

View File

@ -3,25 +3,25 @@
Selecting alphabetically first user by name. Selecting alphabetically first user by name.
<code> <code type="sql">
SELECT MIN(u.name) FROM User u SELECT MIN(u.name) FROM User u
</code> </code>
Selecting the sum of all Account amounts. Selecting the sum of all Account amounts.
<code> <code type="sql">
SELECT SUM(a.amount) FROM Account a SELECT SUM(a.amount) FROM Account a
</code> </code>
* Using an aggregate function in a statement containing no GROUP BY clause, results in grouping on all rows. In the example above we fetch all users and the number of phonenumbers they have. * Using an aggregate function in a statement containing no GROUP BY clause, results in grouping on all rows. In the example above we fetch all users and the number of phonenumbers they have.
<code> <code type="sql">
SELECT u.*, COUNT(p.id) FROM User u, u.Phonenumber p GROUP BY u.id SELECT u.*, COUNT(p.id) FROM User u, u.Phonenumber p GROUP BY u.id
</code> </code>
* The HAVING clause can be used for narrowing the results using aggregate values. In the following example we fetch all users which have atleast 2 phonenumbers * The HAVING clause can be used for narrowing the results using aggregate values. In the following example we fetch all users which have atleast 2 phonenumbers
<code> <code type="sql">
SELECT u.* FROM User u, u.Phonenumber p HAVING COUNT(p.id) >= 2 SELECT u.* FROM User u, u.Phonenumber p HAVING COUNT(p.id) >= 2
</code> </code>

View File

@ -11,7 +11,7 @@ DQL supports two kinds of joins INNER JOINs and LEFT JOINs. For each joined comp
* The default join type is {{LEFT JOIN}}. This join can be indicated by the use of either {{LEFT JOIN}} clause or simply '{{,}}', hence the following queries are equal: * The default join type is {{LEFT JOIN}}. This join can be indicated by the use of either {{LEFT JOIN}} clause or simply '{{,}}', hence the following queries are equal:
<code> <code type="sql">
SELECT u.*, p.* FROM User u LEFT JOIN u.Phonenumber SELECT u.*, p.* FROM User u LEFT JOIN u.Phonenumber
SELECT u.*, p.* FROM User u, u.Phonenumber p SELECT u.*, p.* FROM User u, u.Phonenumber p
@ -21,32 +21,32 @@ The recommended form is the first one.
* {{INNER JOIN}} produces an intersection between two specified components (that is, each and every record in the first component is joined to each and every record in the second component). So basically {{INNER JOIN}} can be used when you want to efficiently fetch for example all users which have one or more phonenumbers. * {{INNER JOIN}} produces an intersection between two specified components (that is, each and every record in the first component is joined to each and every record in the second component). So basically {{INNER JOIN}} can be used when you want to efficiently fetch for example all users which have one or more phonenumbers.
<code> <code type="sql">
SELECT u.*, p.* FROM User u INNER JOIN u.Phonenumber p SELECT u.*, p.* FROM User u INNER JOIN u.Phonenumber p
</code> </code>
By default DQL auto-adds the primary key join condition, so for DQL query: By default DQL auto-adds the primary key join condition, so for DQL query:
<code> <code type="sql">
SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber
</code> </code>
Would have a SQL equivalent: Would have a SQL equivalent:
<code> <code type="sql">
SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = p.user_id SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = p.user_id
</code> </code>
+++ ON keyword +++ ON keyword
If you want to override this behaviour and add your own custom join condition you can do it with the {{ON}} keyword. Consider the following DQL query: If you want to override this behaviour and add your own custom join condition you can do it with the {{ON}} keyword. Consider the following DQL query:
<code> <code type="sql">
SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber ON u.id = 2 SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber ON u.id = 2
</code> </code>
This query would be converted into SQL: This query would be converted into SQL:
<code> <code type="sql">
SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = 2 SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = 2
</code> </code>
@ -54,12 +54,12 @@ SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id
Most of the time you don't need to override the primary join condition, rather you may want to add some custom conditions. This can be achieved with the {{WITH}} keyword. Most of the time you don't need to override the primary join condition, rather you may want to add some custom conditions. This can be achieved with the {{WITH}} keyword.
DQL: DQL:
<code> <code type="sql">
SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber WITH u.id = 2 SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber WITH u.id = 2
</code> </code>
SQL: SQL:
<code> <code type="sql">
SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = p.user_id AND u.id = 2 SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = p.user_id AND u.id = 2
</code> </code>

View File

@ -47,13 +47,13 @@ DQL overcomes this problem with subqueries and with complex but efficient subque
DQL QUERY: DQL QUERY:
<code> <code type="sql">
SELECT u.id, u.name, p.* FROM User u LEFT JOIN u.Phonenumber p LIMIT 20 SELECT u.id, u.name, p.* FROM User u LEFT JOIN u.Phonenumber p LIMIT 20
</code> </code>
SQL QUERY: SQL QUERY:
<code> <code type="sql">
SELECT SELECT
e.id AS e__id, e.id AS e__id,
e.name AS e__name, e.name AS e__name,
@ -72,13 +72,13 @@ In the next example we are going to fetch first 20 users and all their phonenumb
DQL QUERY: DQL QUERY:
<code> <code type="sql">
SELECT u.id, u.name, p.* FROM User u LEFT JOIN u.Phonenumber p LIMIT 20 SELECT u.id, u.name, p.* FROM User u LEFT JOIN u.Phonenumber p LIMIT 20
</code> </code>
SQL QUERY: SQL QUERY:
<code> <code type="sql">
SELECT SELECT
e.id AS e__id, e.id AS e__id,
e.name AS e__name, e.name AS e__name,

View File

@ -11,7 +11,7 @@ Syntax:
Examples: Examples:
<code> <code type="sql">
FROM User u LEFT JOIN u.Phonenumber p FROM User u LEFT JOIN u.Phonenumber p
ORDER BY u.name, p.phonenumber ORDER BY u.name, p.phonenumber
@ -21,7 +21,7 @@ FROM User u, u.Email e
In order to sort in reverse order you can add the DESC (descending) keyword to the name of the column in the ORDER BY clause that you are sorting by. The default is ascending order; this can be specified explicitly using the ASC keyword. In order to sort in reverse order you can add the DESC (descending) keyword to the name of the column in the ORDER BY clause that you are sorting by. The default is ascending order; this can be specified explicitly using the ASC keyword.
<code> <code type="sql">
FROM User u LEFT JOIN u.Email e FROM User u LEFT JOIN u.Email e
ORDER BY e.address DESC, u.id ASC; ORDER BY e.address DESC, u.id ASC;
</code> </code>

View File

@ -1,6 +1,6 @@
{{SELECT}} statement syntax: {{SELECT}} statement syntax:
<code> <code type="sql">
SELECT SELECT
[ALL | DISTINCT] [ALL | DISTINCT]
<select_expr>, ... <select_expr>, ...
@ -18,19 +18,19 @@ The {{SELECT}} statement is used for the retrieval of data from one or more comp
* Each {{select_expr}} indicates a column or an aggregate function value that you want to retrieve. There must be at least one {{select_expr}} in every {{SELECT}} statement. * Each {{select_expr}} indicates a column or an aggregate function value that you want to retrieve. There must be at least one {{select_expr}} in every {{SELECT}} statement.
<code> <code type="sql">
SELECT a.name, a.amount FROM Account a SELECT a.name, a.amount FROM Account a
</code> </code>
* An asterisk can be used for selecting all columns from given component. Even when using an asterisk the executed sql queries never actually use it (Doctrine converts asterisk to appropriate column names, hence leading to better performance on some databases). * An asterisk can be used for selecting all columns from given component. Even when using an asterisk the executed sql queries never actually use it (Doctrine converts asterisk to appropriate column names, hence leading to better performance on some databases).
<code> <code type="sql">
SELECT a.* FROM Account a SELECT a.* FROM Account a
</code> </code>
* {{FROM}} clause {{components}} indicates the component or components from which to retrieve records. * {{FROM}} clause {{components}} indicates the component or components from which to retrieve records.
<code> <code type="sql">
SELECT a.* FROM Account a SELECT a.* FROM Account a
SELECT u.*, p.*, g.* FROM User u LEFT JOIN u.Phonenumber p LEFT JOIN u.Group g SELECT u.*, p.*, g.* FROM User u LEFT JOIN u.Phonenumber p LEFT JOIN u.Group g
@ -38,26 +38,26 @@ SELECT u.*, p.*, g.* FROM User u LEFT JOIN u.Phonenumber p LEFT JOIN u.Group g
* The {{WHERE}} clause, if given, indicates the condition or conditions that the records must satisfy to be selected. {{where_condition}} is an expression that evaluates to true for each row to be selected. The statement selects all rows if there is no {{WHERE}} clause. * The {{WHERE}} clause, if given, indicates the condition or conditions that the records must satisfy to be selected. {{where_condition}} is an expression that evaluates to true for each row to be selected. The statement selects all rows if there is no {{WHERE}} clause.
<code> <code type="sql">
SELECT a.* FROM Account a WHERE a.amount > 2000 SELECT a.* FROM Account a WHERE a.amount > 2000
</code> </code>
* In the {{WHERE}} clause, you can use any of the functions and operators that DQL supports, except for aggregate (summary) functions * In the {{WHERE}} clause, you can use any of the functions and operators that DQL supports, except for aggregate (summary) functions
* The {{HAVING}} clause can be used for narrowing the results with aggregate functions * The {{HAVING}} clause can be used for narrowing the results with aggregate functions
<code> <code type="sql">
SELECT u.* FROM User u LEFT JOIN u.Phonenumber p HAVING COUNT(p.id) > 3 SELECT u.* FROM User u LEFT JOIN u.Phonenumber p HAVING COUNT(p.id) > 3
</code> </code>
* The {{ORDER BY}} clause can be used for sorting the results * The {{ORDER BY}} clause can be used for sorting the results
<code> <code type="sql">
SELECT u.* FROM User u ORDER BY u.name SELECT u.* FROM User u ORDER BY u.name
</code> </code>
* The {{LIMIT}} and {{OFFSET}} clauses can be used for efficiently limiting the number of records to a given {{row_count}} * The {{LIMIT}} and {{OFFSET}} clauses can be used for efficiently limiting the number of records to a given {{row_count}}
<code> <code type="sql">
SELECT u.* FROM User u LIMIT 20 SELECT u.* FROM User u LIMIT 20
</code> </code>

View File

@ -1,6 +1,6 @@
{{UPDATE}} statement syntax: {{UPDATE}} statement syntax:
<code> <code type="sql">
UPDATE //component_name// UPDATE //component_name//
SET //col_name1//=//expr1// [, //col_name2//=//expr2// ...] SET //col_name1//=//expr1// [, //col_name2//=//expr2// ...]
[WHERE //where_condition//] [WHERE //where_condition//]

View File

@ -1,6 +1,6 @@
Syntax: Syntax:
<code> <code type="sql">
WHERE <where_condition> WHERE <where_condition>
</code> </code>