Something like this ?
SELECT ID, CMD
WHERE cmd LIKE %httpd%
GROUP BY ppid
HAVING COUNT(ppid) = 1
Question
My problem is about extraction from my Mysql DB.
In my DB I have inventory Process from Computer. Here is an example of line in my DB.
ID CMD PID PPID
1000 /usr/sbin/httpd 9260 12600
1001 /usr/sbin/httpd 9261 12600
1002 /usr/sbin/httpd 9262 12600
1003 /usr/sbin/httpd 9263 12600
1004 /usr/sbin/httpd 12600 50
OK, I want to only select the line :
1004 /usr/sbin/httpd 12600 50
Actually my code PHP select the 5 lines.
But now I want to put a php code for selecting the CMD which not created by Parent Process between them. In the example the line with PPID 50 is the good one, her parent process is not here.
I really don't know what I can make, but that is my example.
SELECT ID, CMD
WHERE cmd LIKE %httpd% AND IF ppid IS NOT EQUAL TO OTHER ppid WHICH HAVE THE SAME cmd;
I hope you can help me. Sorry my problem is complicated, I am bad for explain it.
Solution 2
Something like this ?
SELECT ID, CMD
WHERE cmd LIKE %httpd%
GROUP BY ppid
HAVING COUNT(ppid) = 1
OTHER TIPS
You must find the items without parents inside Inventory. To do this you must do a subquery for the items that do have parents. This should do the trick. This also accounts for the single child possibility.
SELECT i.*
FROM Inventory i
LEFT JOIN
(-- with parents in Inventory
SELECT k.PID
FROM Inventory j
JOIN Inventory k ON k.PPID = j.PID) l ON l.PID = i.PID
WHERE l.PID IS NULL
do a self join to the table like this:
SELECT i.ID, i.CMD,iPID,i.PPID from inventory i,inventory j WHERE i.PID <> j.PPID
In the above example inventory
is the table name (assuming).
try like this:
SELECT ID, CMD WHERE cmd LIKE '%httpd%' GROUP BY cmd;