Home » SQL & PL/SQL » SQL & PL/SQL » Maximum Date
Maximum Date [message #600844] Wed, 13 November 2013 01:46 Go to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
what will be query to take out maximum chECK_DATE of employees from employee table but the result do not show previous check date, only it will show current check date For example for employee - 104,253 -10/25/2013----->current_date




company - employee - checkDate
1 - 104,253 - 10/25/2013
1 - 104,240- 10/25/2013
1 - 104,253- 10/11/2013
1 - 104,240- 10/11/2013

[Updated on: Wed, 13 November 2013 01:47]

Report message to a moderator

Re: Maximum Date [message #600848 is a reply to message #600844] Wed, 13 November 2013 02:26 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Use the max function and the group by clause. And read the documentation
Re: Maximum Date [message #600849 is a reply to message #600844] Wed, 13 November 2013 02:50 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
sahnra wrote on Wed, 13 November 2013 13:16
For example for employee - 104,253 -10/25/2013----->current_date


You have employee as 104,253. So, 104 and 253 are two different employees, right? Or, are you storing it together in your employee table?
Re: Maximum Date [message #600851 is a reply to message #600849] Wed, 13 November 2013 02:57 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
104253 is a single employee ID
Re: Maximum Date [message #600854 is a reply to message #600851] Wed, 13 November 2013 04:30 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
sahnra wrote on Wed, 13 November 2013 08:57
104253 is a single employee ID

Have you read the documentation that I linked to? Have you resolved your 'issue'?
Re: Maximum Date [message #600858 is a reply to message #600854] Wed, 13 November 2013 05:10 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
Yup but the query is only searching Max value and arranging them in descending order but not deleting the other value instead of max value
Re: Maximum Date [message #600859 is a reply to message #600858] Wed, 13 November 2013 05:14 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
1. Post your query
2. Quote your post where you said that you wanted to delete data.
3. Show us that you have looked up the documentation for the delete statement.
4. Show us that you have tried to apply your newly gained knowledge of the delete statement to your issue (it's fine if you have failed, just show us that you have put some effort in).
Re: Maximum Date [message #600861 is a reply to message #600859] Wed, 13 November 2013 05:29 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
SELECT A.COMPANY, A.Process_level, MAX(B.CHECK_DATE) Last_check_date
FROM LAWSON.EMPLOYEE A, LAWSON.PAYMASTR B,

LAWSON.COMPROF C, LAWSON.TAXGROUP D WHERE A.EMPLOYEE = B.EMPLOYEE
AND A.PROCESS_LEVEL = C.PROCESS_LEVEL
AND A.COMPANY = B.COMPANY
AND A.COMPANY = C.COMPANY
And A.company = D.company
and A.PROCESS_LEVEL= D.process_level
AND C.COMPANY = '1'
Group by A.COMPANY,A.Process_level, A.EMPLOYEE
ORDER BY B.CHECK_DATE DESC
Re: Maximum Date [message #600862 is a reply to message #600861] Wed, 13 November 2013 05:31 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
In this query i want only one check date which is max(Check_date)of employee and when i use Distinct(Employee)to delete the duplicate employee it's not excepting distinct
Re: Maximum Date [message #600863 is a reply to message #600862] Wed, 13 November 2013 05:42 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
shouldn't the list of columns in the select bit match the list of columns in the group by?

Show us the delete you used.
Re: Maximum Date [message #600864 is a reply to message #600863] Wed, 13 November 2013 05:42 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
And can you please read and follow How to use [code] tags and make your code easier to read?
Re: Maximum Date [message #600865 is a reply to message #600862] Wed, 13 November 2013 05:43 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
You are including columns in your query that you have not mentioned in your original op with sample data. It's time to start over.

Provide a working test case (create table and insert statements)
Provide expected output and an explanation of that output.
Use code tags whenever you post code (it makes it much easier to read).
You seem to be mixing up terms too. ONLY use the term delete if you want to permanently REMOVE rows from a table. (Based on what you have posted, you don't seem to want to do that)
Re: Maximum Date [message #600866 is a reply to message #600862] Wed, 13 November 2013 05:45 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
In the OP you just talked about a single table "EMPLOYEES", you never talked about a join of 4 tables, so obviously the output could be different depending on the semantic of your GROUP by clause and the structure of the join.

[Edit]: Sorry I didn't see pablolee's remark, before posting Smile

[Updated on: Wed, 13 November 2013 05:47]

Report message to a moderator

Re: Maximum Date [message #600869 is a reply to message #600866] Wed, 13 November 2013 06:18 Go to previous messageGo to next message
sahnra
Messages: 39
Registered: November 2013
Location: India
Member
Sorry for that can you please let me know one thing how i can remove duplicate of employee from this query


SELECT A.COMPANY, a. EMPLOYEE, A.Process_level, MAX(B.CHECK_DATE) Last_check_date
FROM LAWSON.EMPLOYEE A, LAWSON.PAYMASTR B,

LAWSON.COMPROF C, LAWSON.TAXGROUP D WHERE A.EMPLOYEE = B.EMPLOYEE
AND A.PROCESS_LEVEL = C.PROCESS_LEVEL
AND A.COMPANY = B.COMPANY
AND A.COMPANY = C.COMPANY
And A.company = D.company
and A.PROCESS_LEVEL= D.process_level
AND C.COMPANY = '1'
Group by A.COMPANY,A.Process_level, A.EMPLOYEE
ORDER BY B.CHECK_DATE DESC

[Updated on: Wed, 13 November 2013 06:19]

Report message to a moderator

Re: Maximum Date [message #600871 is a reply to message #600869] Wed, 13 November 2013 06:42 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Seems that you have not read yet the previous comments and suggestions (specially pablolee's previous comment).
Re: Maximum Date [message #600873 is a reply to message #600864] Wed, 13 November 2013 06:56 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
I don't appreciate having to ask this multiple times:

cookiemonster wrote on Wed, 13 November 2013 11:42
And can you please read and follow How to use [code] tags and make your code easier to read?


Do so before your next post please.

Past that, the only why that query is giving dupes is if the EMPLOYEE table contains multiple records with the same EMPLOYEE and different COMPANY or Process_level.
So you need to show us (as already asked) an example of your current data and an example of the expected output.
Re: Maximum Date [message #600874 is a reply to message #600869] Wed, 13 November 2013 07:33 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
sahnra wrote on Wed, 13 November 2013 13:18
Sorry for that can you please let me know one thing how i can remove duplicate of employee from this query

Just remove it (column EMPLOYEE) from SELECT and GROUP BY clauses. If case of need, introduce any aggregate function on that column fulfilling the exact requirements. In fact, it is impossible to deduce it from your posts. More precisely, it is impossible to deduce anything from your posts at all as they are continually changing.

If you want more precise answer/solution, just re-read pablolee's post (http://www.orafaq.com/forum/mv/msg/190313/600865/#msg_600865) and start collecting the demanding info. I believe that you may find the solution yourself when you try fulfilling it.
Re: Maximum Date [message #600877 is a reply to message #600869] Wed, 13 November 2013 08:19 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
sahnra wrote on Wed, 13 November 2013 17:48
can you please let me know one thing how i can remove duplicate of employee from this query


This link might help you in better understanding on how to remove duplicates.
Previous Topic: update
Next Topic: Difference between null & Empty string
Goto Forum:
  


Current Time: Wed Apr 24 03:05:48 CDT 2024