1

I am using MySQL database. There is a cars table in my database, cars table has several columns, one of the columns is named "country".

I use the following query to fetch 2000 cars from the table:

SELECT * FROM cars LIMIT 1,2000;

I got the result successfully, the country column shows all the countries.

However, when I use the following query to fetch 2000 cars from the table:

SELECT country FROM cars LIMIT 1,2000;

I got 2000 results but the country column now are all empty values. Why??? What could be the reason?

(I have only 100 car object have empty country, weired I got all empty country value for 2000 results in the 2nd query.)

1 Answer 1

1

Without a WHERE or ORDER BY, the database is free to decide which rows it wants to return, and there's no guarantee which ones it will decide are the quickest to fetch.

You need to add a WHERE condition at least:

SELECT country FROM cars WHERE country IS NOT NULL LIMIT 1,2000;
Sign up to request clarification or add additional context in comments.

4 Comments

empty values are explained, But why he is getting only 20 rows? @Ken White
Hi, I add where clause, it returns to me the same thing, besides, I have only 100 cars have empty country value, how come 2000 country values are empty in my 2nd query.
Hey, that 20 results is my typo, I got 2000 empty country car objects
I'm not sure he did. The query says '1,2000', the next to last paragraph says "I got 20 results", and the final paragraph says "I got all empty country value for 2000 results". There's a lot of inconsistency there. I think it's 2000 results (I did have a typo in my answer, though; I missed the , in the limit clause.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.