shebbycs Posted November 5, 2013 Share Posted November 5, 2013 I had data like this empno ename job mgr hiredate sal comm deptno 7369 SMITH CLERK 7902 1980-12-17 800 NULL 20 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 7566 JONES MANAGER 7839 1981-04-02 2975 NULL 20 1) Display the name and hire date of the employee who was hired first without using subquery 2) Display the name and hire date of the employee who was hired last without using subquery Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/ Share on other sites More sharing options...
Psycho Posted November 5, 2013 Share Posted November 5, 2013 And what have you tried so far and/or what questions do you have? this forum is for people to get help with code they have written, not for people to do your homework for you. Unless your instructor is a moron I suspect he has recently gone over several different SQL functions recently. Go over those and give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457003 Share on other sites More sharing options...
shebbycs Posted November 5, 2013 Author Share Posted November 5, 2013 And what have you tried so far and/or what questions do you have? this forum is for people to get help with code they have written, not for people to do your homework for you. Unless your instructor is a moron I suspect he has recently gone over several different SQL functions recently. Go over those and give it a try. I had try for the date i using for max and min but when to call together with name I did not manage to make it because it will showing many name since i used the group by that part I stuck Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457011 Share on other sites More sharing options...
Psycho Posted November 5, 2013 Share Posted November 5, 2013 You want a single record. GROUP BY is used to "group" records to get things such as the SUM, AVG, etc across many records. There are two specific functions you will want to use to get the records in a particular order and to select only the one you want for each query. Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457012 Share on other sites More sharing options...
shebbycs Posted November 5, 2013 Author Share Posted November 5, 2013 You want a single record. GROUP BY is used to "group" records to get things such as the SUM, AVG, etc across many records. There are two specific functions you will want to use to get the records in a particular order and to select only the one you want for each query. ok let said I had called the min hiredate for the first hired how can i call that person only ? because if i did like min hiredate and min ename it will not give the first hired date person Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457013 Share on other sites More sharing options...
Barand Posted November 5, 2013 Share Posted November 5, 2013 Have you considered sorting the records and just returning the first record? Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457021 Share on other sites More sharing options...
Psycho Posted November 5, 2013 Share Posted November 5, 2013 ok let said I had called the min hiredate for the first hired how can i call that person only ? because if i did like min hiredate and min ename it will not give the first hired date person MIN() is another GROUP BY function. This is not a problem to be resolved with grouping. See Barand's response above. He decided to throw you a bone. Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457080 Share on other sites More sharing options...
shebbycs Posted November 6, 2013 Author Share Posted November 6, 2013 Have you considered sorting the records and just returning the first record? SELECT HIREDATE FROM EMP WHERE ROWNUM<=1 ORDER BY HIREDATE; ? is it like this? Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457119 Share on other sites More sharing options...
shebbycs Posted November 6, 2013 Author Share Posted November 6, 2013 but how to call first and last in sql developer if first and last is invalid identifier Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457120 Share on other sites More sharing options...
Psycho Posted November 6, 2013 Share Posted November 6, 2013 Not quite. The ORDER BY will ensure you are getting the records in order so the newest is first or the oldest is first (based on whether you sort in ascending or descending). But, to get the first record you want to use LIMIT SELECT HIREDATE FROM EMP ORDER BY HIREDATE ASC <-- or "DESC" LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457264 Share on other sites More sharing options...
Barand Posted November 6, 2013 Share Posted November 6, 2013 You were asked for the name too! Quote Link to comment https://forums.phpfreaks.com/topic/283607-display-name-and-hiredate/#findComment-1457271 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.