Selecting all ids(rows) except one id(row) in sql using php

  • 0

Sample Query, here we select all page ids and its count but id except a particular number, Query inside braces of NOT IN condition:

“SELECT `page_id`, COUNT(`page_id`) AS `total` FROM `table.comments` WHERE `page_id` NOT IN (
SELECT `id` FROM pages WHERE `identifier` = ‘$except_id’) GROUP BY `page_id`”

Sample Query, here we select all page ids and its count but id except a particular number, Query inside braces of NOT IN condition: “SELECT `page_id`, COUNT(`page_id`) AS `total` FROM `table.comments` WHERE `page_id` NOT IN ( SELECT `id` FROM pages WHERE `identifier` = ‘$except_id’) GROUP BY `page_id`”

Sample Query, here we select all page ids and its count but id except a particular number, Query inside braces of NOT IN condition: “SELECT `page_id`, COUNT(`page_id`) AS `total` FROM `table.comments` WHERE `page_id` NOT IN ( SELECT `id` FROM pages WHERE `identifier` = ‘$except_id’) GROUP BY `page_id`”