学说更新查询我愿做一个更新询问有那样的极限:与LIMIT
UPDATE anytable SET anycolumn = 'anyvalue' WHERE anothercolumn='anothervalue' LIMIT 20
这怎么可能教义2.1?
学说更新查询我愿做一个更新询问有那样的极限:与LIMIT
UPDATE anytable SET anycolumn = 'anyvalue' WHERE anothercolumn='anothervalue' LIMIT 20
这怎么可能教义2.1?
不是学说特定的,但也许可以用子查询?
UPDATE messages SET test_read=1
WHERE id IN (
SELECT id FROM (
SELECT id FROM messages
ORDER BY date_added DESC
LIMIT 5, 5
) tmp
);
编辑:
,你可以去一下两种不同的方式:
1 - 创建查询直接使用DQL:
$query = $entityManager->createQuery('UPDATE Entities\User u SET u.someValue = newValue WHERE u.id = someId');
// this will add the LIMIT statement
$query->setMaxResults(20);
$query->execute();
2 - 创建使用QueryBuilder进行查询:
$qb = $this->_em->createQueryBuilder();
$query = $qb->update('Entities\User', 'u')
->set('u.someValue', newValue)
->where('u.id = someId')
->getQuery();
// this will add the LIMIT statement
$query->setMaxResults(20);
$query->execute();
你应该做的:回声$query->getSQL();
检查出这两个
编辑生成的SQL: 另一种选择(不强烈推荐)是使用Native SQL
我发现我有从entityManager获取连接并调用executeUpdate:
$em->getConnection()->executeUpdate(
"UPDATE anytable SET anycolumn = 'anyvalue'
WHERE anothercolumn='anothervalue'
LIMIT 20");
该说:
If you want to execute DELETE, UPDATE or INSERT statements the Native SQL API cannot be used and will probably throw errors. Use EntityManager#getConnection() to access the native database connection and call the executeUpdate() method for these queries.
'选择':错误:类 '(' 不defined' – 2013-07-05 13:15:37