catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

Clause Top doesn't exist #354

Closed rikirenz closed 7 years ago

rikirenz commented 8 years ago

I need to select only the first 10 rows for a query. But there is not any kind of information about the TOP clause in the documentation. Which is the right way to select a specific number of rows wit Medoo?

baschwartz commented 8 years ago

$database->select("account", "user_name", [
    "AND" => [
        "user_name" => "foo",
        "LIMIT" => 10
]);
SyuTingSong commented 8 years ago

Are you using Oracle or MS SQL Server?

Because of most people use MySQL/SQLite/PostgreSQL with Medoo, no body write code for TOP at present.

Here is the Oracle way to fetch first 10 rows in SQL

SELECT * FROM user FETCH FIRST 10 ROWS ONLY;

And the second 10 rows

SELECT * FROM user OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;

I heard that Microsoft SQL Server supports this way since ver 2012.

The patch for oracle limit is in commit f9023a98c64