PhpDeveloper
Programmer
I am trying to write a query to retrieve records that contain the latest (maximum) version number and action can’t be “Deletion”.
Sample table is listed below named as Mytable:
ID Version Action Name
1 1 Data1
2 1 Data2
1 2 Modification Data1
3 1 Data3
2 2 Modification Data2
1 3 Deletion Data1
My query is like this:
Select * from Mytable where (Action<>’Deletion’ or Action IS NULL)
But you know this query only return the following records with one Data3 and two Data2 like this:
ID Version Action Name
2 1 Data2
3 1 Data3
2 2 Modification Data2
So which means I need the query that can retrieve records as following:
ID Version Action Name
3 1 Data3
2 2 Modification Data2
Since the record of Data1 is marked as “Deletion” with its latest verion number, so it should NOT be displayed. But I only need the record of Data2 containing the latest version number 2. I know I am stuck with adding the selection of max(Version_Num) in this query, could someone kindly help me out?
Sample table is listed below named as Mytable:
ID Version Action Name
1 1 Data1
2 1 Data2
1 2 Modification Data1
3 1 Data3
2 2 Modification Data2
1 3 Deletion Data1
My query is like this:
Select * from Mytable where (Action<>’Deletion’ or Action IS NULL)
But you know this query only return the following records with one Data3 and two Data2 like this:
ID Version Action Name
2 1 Data2
3 1 Data3
2 2 Modification Data2
So which means I need the query that can retrieve records as following:
ID Version Action Name
3 1 Data3
2 2 Modification Data2
Since the record of Data1 is marked as “Deletion” with its latest verion number, so it should NOT be displayed. But I only need the record of Data2 containing the latest version number 2. I know I am stuck with adding the selection of max(Version_Num) in this query, could someone kindly help me out?