我必须在PHP中使用SQLServer执行下面的查询,但我不能在Microsoft查询中使用缺少的LIMIT
子句。
$SqlTabelaAtual="SELECT *
FROM BusinessCadTabPreco
RIGHT JOIN BusinessCadTabPrecoItem ON BusinessCadTabPreco.CdTabela = BusinessCadTabPrecoItem.CdTabela
WHERE BusinessCadTabPreco.CdEmpresa =01
AND CdProduto =".$row['CdProduto']."
ORDER BY BusinessCadTabPreco.DtSincronizar DESC LIMIT 1
答案 0 :(得分:2)
使用此代码,在 SQLServer 中,关键字限制为 TOP
$SqlTabelaAtual="SELECT TOP 1 *
FROM BusinessCadTabPreco
RIGHT JOIN BusinessCadTabPrecoItem ON BusinessCadTabPreco.CdTabela = BusinessCadTabPrecoItem.CdTabela
WHERE BusinessCadTabPreco.CdEmpresa =01
AND CdProduto =".$row['CdProduto']."
ORDER BY BusinessCadTabPreco.DtSincronizar DESC"
答案 1 :(得分:0)
您可以通过将TOP表达式添加到SELECT子句来限制返回的记录。
<强>用法强>
/* Returns the first 10 records.
* Combine with an ORDER BY if you want control over the records returned.
*/
SELECT TOP 10
Id
FROM
TableName
;
或者
-- Percent return.
SELECT TOP 10 PERCENT
Id
FROM
TableName
;