Why are there different results when narrowing the columns and fetching only the first row?

I am running two queries in DB2

SELECT * from mrptable FETCH FIRST ROW ONLY
--result for mrpcolumn = 1150131

SELECT mrpcolumn FROM mrptable FETCH FIRST ROW ONLY
--result for mrpcolumn = 0

      

Why will these two results be different?

+3


source to share


1 answer


You don't have a suggestion order by

for any query, so the ordering of the result set is undefined. You can even run the same query twice and get different results.

There are many reasons why the result sets will not be in the same order. Most likely you have an index on mrpcolumn

. This index spans the second query, so the query can use the index to get one row.

The first will go to the data files.



Another reason could be execution in a parallel environment where it is undefined which thread / process returns the first value.

When using sentences, fetch first

you should usually use order by

.

+8


source







All Articles