I am trying to read 1000 records from any database at a time. I assume we don't know the name of columns and type of columns so I always pick the first one in the table to do the ORDER BY. Does it matter which one in the table to pick for using ORDER BY? I am not very good at database stuff and right now I am learning. If picking a good column can speed up the query execution to return the result set, then what type should I be looking for?
My codes:
if (SQLServerDatabase) {
String query = "SELECT * FROM "+tablename+" ORDER BY "+columnnames.get(0)+" OFFSET "+offset+" ROWS FETCH NEXT "+size+" ROWS ONLY;";
rs = stmt.executeQuery(query);
} else if (MySQLDatabase) {
String query = "SELECT * FROM "+tablename+" LIMIT "+offset+", "+size+";";
rs = stmt.executeQuery(query);
}
Note: columnnames is a list