Return to Snippet

Revision: 8438
at September 21, 2008 16:03 by stavelin


Initial Code
function findunUsedCats($aid){
	$query = "SELECT cat_tbl.cid, cat_tbl.category FROM cat_tbl WHERE cat_tbl.category NOT IN (SELECT cat_tbl.category FROM cat_tbl, art_has_cat_tbl WHERE cat_tbl.cid = art_has_cat_tbl.cid AND aid =$aid);";
	$query = mysql_query($query)or die("nope..".mysql_error());
	return $query;
}

Initial URL


Initial Description
It's easy to find the categories used on one item, but find all categories NOT used on current item?
This snippet stores a "NOT IN" query.

This is used with PHP & mySQL. The query can be written differently on other databases, but this seems to work with mySQL.

Initial Title
Find all categories NOT used in current item

Initial Tags
query

Initial Language
SQL