Page 1 of 1

Exclude a cat_id in this SQL

Posted: Mon Mar 28, 2011 11:17 pm
by danjapro
I am not the best at sql and php, but.
I am easier with .net apps and sql query.

How do you include or exlude a specific list of items based on a set id like "cat_id", exlude specifi cat_id?

What is correct way to write it?

Code: Select all

	$db	 =& JFactory::getDBO();
	
	$query  = "	SELECT
							* 
					FROM
							".$db->nameQuote('#__community_videos')."
					WHERE
							".$db->nameQuote('published')."=".$db->quote(1)."
					AND
							".$db->nameQuote('permissions')."=".$db->quote(0)."
					AND NOT
						                ".$db->nameQuote('cat_id')."=".$db->quote(5)."
																																								
					ORDER BY
							".$db->nameQuote('created')." DESC
					LIMIT 
							".$limit;

	$db->setQuery( $query );
	
	$result = $db->loadObjectList();







Re: Exclude a cat_id in this SQL

Posted: Tue Mar 29, 2011 12:50 pm
by social_experiment
Wouldn't it be easier to use the not equal operator (!=) ?