Is it possible to have 2 restrictions in a MySQL query?

Ok, here is the situation (using PHP / MySQL) you get the results from a large mysql table, let's say your mysql query returns 10,000 results of matching, and you have a page script to show 20 results per page, your query may look like this :

So page 1 request

SELECT column 
FROM table_name 
WHERE userId=1 
AND somethingelse=something else
LIMIT 0,20

So page 2 request

SELECT column 
FROM table_name 
WHERE userId=1 
AND somethingelse=something else
LIMIT 20,40

Now you get 20 results at a time, but there are 10,000 rows that match your search criteria,

How can you return only 3,000 of 10,000 results and still perform a search query of 20 per page using LIMIT 20 in your query?

I thought this was not possible, but myspace does it there, it views the page somewhere, I know that they do not use php / mysql, but how can this be achieved?

UPDATE

, , , , 3000?

+3
6

PHP, , , LIMIT 3000, 20 , .

- ?

Update:

MySQL LIMIT.

SQL_CALC_FOUND_ROWS , MySQL , .., , .

- :

SELECT  column 
FROM    table_name 
WHERE   userId=1 
        AND somethingelse='something else'
LIMIT 0, 20

MySQL 20, .

, : 50 1,000,000, .

ORDER BY , MySQL, , , 20.

10,000: " " 20 , ( ) , .

, .

MySQL, , . , :

SELECT  column 
FROM    (
        SELECT  column
        FROM    table_name 
        WHERE   userId=1 
                AND somethingelse='something else'
        LIMIT 3000
        )
LIMIT 0, 20

, .

MySQL 3,000, ( ) LIMIT .

+4

-, LIMIT , 20 - .

, , , , , , Offset + Limit <= 3000

+1

Sohnee, ( ) 3000 SQL, array_slice php, .

+1

...

SELECT name FROM (
   SELECT name FROM tblname LIMIT 0, 3000
) `Results` LIMIT 20, 40

Or with a temporary table in which you select all 3,000 rows in the temp table, and then a page with a temporary row identifier that will be sequential.

0
source

You can specify the limit as a function of page number (20 * p, 20 * p + 2) in your php code and limit the value of page number to 150.

0
source

Or you can get 3000 entries and them using jquery tabs, dividing entries by 20 per page.

0
source

Source: https://habr.com/ru/post/1713834/


All Articles