LIMIT and OFFSET duplicates data in mysql

Asked

Viewed 153 times

0

I have a table in mysql but when using LIMIT and OFFSET I have an unwanted return, 1 data repeats to each search.

Look at the table:

tabela

then use the following command:

SELECT funcionario.nome
FROM funcionario
LIMIT 0, 2

get back to me: busca 1

after the second command:

SELECT * 
FROM `funcionario`
LIMIT 1,2

got the return: inserir a descrição da imagem aqui

how to do this type of query without repeating data ?

2 answers

2


The LIMIT you put from which line it starts to the line it ends, or the limit number of lines, for example:

If you put LIMIT 1, he will pull the first line, in your case the employee abner. LIMIT 2: Two lines (the employees Abner and g) and so on.

LIMIT 1, 2 will bring two lines starting from the line 1. In the case of your example, will bring starting from the g, up to the second line teste, thus. Put LIMIT 2, 2. It will bring two lines starting from the line 2, in that case, will come the employees teste and joao.

In your example, the ideal is to use LIMIT 0, 2, LIMIT 2, 2, LIMIT 4,2 and so on...

-1

LIMIT and OFFSET do not make data repeat. In the picture I see no repeated data. To not show duplicate value use if DISTINCT.

SELECT DISTINCT functionary.name FROM employee LIMIT 0, 2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.