Leem.fin
Leem.fin

Reputation: 42592

query returns empty value

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.)

Upvotes: 1

Views: 126

Answers (1)

Ken White
Ken White

Reputation: 125651

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;

Upvotes: 1

Related Questions