Skip to content
Advertisement

Select all employees sorted by last name in ascending order

How can I implement SQL query in order to select all employees sorted by last name in ascending order in the following Java class:

public class SqlQueries {
    //Select all employees sorted by last name in ascending order
    //language=HSQLDB
    String select = "";
}

Advertisement

Answer

If there is a separate column for last name then it is very much easy to achieve.

SELECT * FROM EMPLOYEE ORDER BY LAST_NAME ASC;

If there is only one column i.e. full name , then split the string from the last white space and extract the last name.

SELECT * FROM EMPLOYEE ORDER BY SUBSTR(FULL_NAME,INSTR(FULL_NAME,' ',-1)) ASC;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement