This is my full request:
SELECT * FROM `clientgroupassign` LEFT JOIN `clients` ON `clientgroupassign`.clientId = `clients`.clientId LEFT JOIN `users` ON `carerId` = `userId` LEFT JOIN (SELECT * FROM (SELECT * FROM `contacts` WHERE `contactGroup` = 4 ORDER BY `contactId` DESC) as `contacts` GROUP BY (`contactClientId`) ) AS `contacts` ON `contactClientId` = `clients`.clientId WHERE groupId = 4 ORDER BY `clients`.clientId
There is a problem with the third connection causing the script to execute for about 1 minute. When I run it separately in PMA:
SELECT * FROM (SELECT * FROM `contacts` WHERE `contactGroup` = 4 ORDER BY `contactId` DESC) AS `contacts` GROUP BY (`contactClientId`)
still a lot of time to complete.
I want to get one, the last added row from contacts for each client that is in group 4 (the client can be in different groups).
Thanks.
sql php mysql sql-order-by group-by
user2104742
source share