Actually I have a table called users and I have to pull out the child and grandchild users of a specific user like I am trying to get child and grandchild users of user with id 44 and I tried this query but it is giving me some extra users even they are not child or grand child of user 44:
SELECT * FROM `users` WHERE `parent_id`='44' OR `parent_id` IN (SELECT `id` FROM `users` WHERE `parent_id`='44' OR `parent_id` IN (SELECT `id` AS 'curret_id' FROM `users` WHERE `parent_id`='44' OR `parent_id` IN (SELECT `id` FROM `users` WHERE `parent_id`='curret_id')))
Here is CREATE TABLE Syntax for my table if it helps:
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`join_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`fname` varchar(250) NOT NULL,
`lname` varchar(250) NOT NULL,
`email` varchar(250) NOT NULL,
`phone` varchar(250) NOT NULL,
`dob` date NOT NULL,
`user_type` varchar(250) NOT NULL,
`parent_id` int(11) NOT NULL,
`status` varchar(250) NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1;