SELECT DISTINCT g_id, g_name FROM group1 ,category WHERE
group1.g_id NOT IN ((SELECT DISTINCT g_id FROM detail WHERE p_id = '".$_SESSION[sess_id]."' AND c_id = '$val' )) ORDER BY g_id ASC "
SELECT group1.g_id, group1.g_name
FROM group1
LEFT JOIN detail
ON detail.g_id=group1.g_id
AND detail.p_id = '".$_SESSION[sess_id]."'
WHERE detail.g_id is null
GROUP BY group1.g_id
ORDER BY g_id
SELECT a.g_id, a.g_name
FROM group1 a,detail b
WHERE
b.g_id=a.g_id AND
b.p_id = '".$_SESSION['sess_id']."' AND
b.g_id is null
GROUP BY b.g_id
ORDER BY a.g_id
SELECT group1.g_id, group1.g_name
FROM group1
LEFT JOIN detail
ON detail.g_id=group1.g_id
AND detail.p_id = '".$_SESSION[sess_id]."'
WHERE detail.g_id is null
GROUP BY group1.g_id
ORDER BY g_id