SELECT ... FROM ... LEFT JOIN ... WHERE ... GROUP BY ... HAVING ... ORDER BY ... LIMIT ...
SELECT * FROM article a INNER JOIN user u ON a.user_id = u.id WHERE a.active = TRUE:)
SELECT * FROM article a INNER JOIN user u ON (a.user_id = u.id AND a.active = TRUE)
SELECT username AS login FROM user WHERE login = 'foobar':)
SELECT u.username AS login FROM user u WHERE u.username = 'foobar'
SELECT name, amount FROM order
Jérémy | 103 |
Jérémy | 13 |
Tristan | 39 |
Tristan | 199 |
Tristan | 129 |
SELECT name, SUM(amount) FROM orders GROUP BY name
Jérémy | 116 |
Tristan | 367 |
SELECT name, SUM(amount) AS total FROM orders GROUP BY name HAVING total > 200:)
SELECT name, SUM(amount) AS total FROM orders GROUP BY name HAVING SUM(amount) > 200
SELECT name, SUM(amount) AS total GROUP BY name ORDER BY total ASC
SELECT name, amount ORDER BY amount ASC, name DESC
Jérémy | 13 |
Tristan | 39 |
Tristan | 103 |
Jérémy | 103 |
Tristan | 199 |
SELECT name, amount ORDER BY name, amount ASC
Jérémy | 13 |
Jérémy | 39 |
Tristan | 29 |
Tristan | 129 |
Tristan | 199 |
SELECT name, SUM(amount) AS total FROM orders GROUP BY name ORDER BY total DESC LIMIT 0, 2
Le COUNT, GROUP BY et le ORDER BY s'applique sur toute la table
SELECT * FROM orders WHERE id = ANY (SELECT ...)
SELECT * FROM orders WHERE amount > ALL (SELECT ...)
SELECT * FROM orders WHERE EXISTS (SELECT ...)
$this->createQueryBuilder('article')->leftJoin('category'):)
$this->createQueryBuilder('article') ->select('article, category') ->leftJoin('category')
EAGER, LASY
)HYDRATE_OBJECT, HYDRATE_ARRAY, ...
)partial article.{id, title}
)$this->createQueryBuilder('c') ->select('c.id, COUNT(a.id)') ->leftJoin('c.articles', 'a') ->groupBy('a.id')VS
$this->createQueryBuilder('c') ->select([ 'c.id', '(SELECT COUNT(a.id) FROM Model:Article a WHERE a.category = c)' ])
$this ->createQueryBuilder('article') ->select('article, category, tag') ->leftJoin('article.category', 'category') ->leftJoin('article.tags', 'tag')+
$articles->getTags()->count()
$this ->createQueryBuilder('article') ->select([ 'article.id AS articleId', 'article.name AS articleName', 'category.id AS categoryId', 'category.name AS categoryName' '(SELECT COUNT(t.id) FROM Model:Tag t INNER JOIN tag.articles a WITH a = article)' ]) ->leftJoin('article.category', 'category')
Peut être très lent lorsque la requête est complexe ou qu'il y a trop de ligne
Evènement 'knp_paginator.subscriber' et pagination manuel
Utiliser les CASCADE du SGBD au lieu de ceux de Doctrine
@OneToMany(targetEntity="Comment", mappedBy="author", cascade={"remove"})SGBD
@JoinColumn(onDelete="CASCADE")