Index: query.php
===================================================================
--- query.php	(revision 16495)
+++ query.php	(working copy)
@@ -1948,7 +1948,7 @@
 			$clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) );
 
 			$join .= $clauses['join'];
-			$where .= $clauses['where'];
+			$where .= ' AND ' . $clauses['where'];
 
 			if ( empty($post_type) ) {
 				$post_type = 'any';
Index: taxonomy.php
===================================================================
--- taxonomy.php	(revision 16495)
+++ taxonomy.php	(working copy)
@@ -520,13 +520,24 @@
  * @param string $primary_id_column
  * @return string
  */
-function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
+function get_tax_sql( $tax_query, $primary_table, $primary_id_column, $ignore='', $relationship = 'AND', $i = 0 ) {
 	global $wpdb;
 
 	$join = '';
 	$where = '';
-	$i = 0;
 	foreach ( $tax_query as $query ) {
+		
+		if ( is_array( $query ) && array_key_exists ( 'relationship', $query ) ) {
+			$rel = $query['relationship'];
+			unset($query['relationship']);
+			$ret = get_tax_sql($query, $primary_table, $primary_id_column, $ignore, $rel, $i);
+
+			$join .= $ret['join'];
+			$where .= '( ' . $ret['where'] . ' )';
+			$i = $ret['i'];
+			continue;
+		}
+		
 		extract( wp_parse_args( $query, array(
 			'taxonomy' => array(),
 			'terms' => array(),
@@ -539,7 +550,7 @@
 
 		foreach ( $taxonomies as $taxonomy ) {
 			if ( ! taxonomy_exists( $taxonomy ) )
-				return ' AND 0 = 1';
+				return '0 = 1';
 		}
 
 		$taxonomies = "'" . implode( "', '", $taxonomies ) . "'";
@@ -579,9 +590,10 @@
 			$join .= " INNER JOIN $wpdb->term_relationships";
 			$join .= $i ? " AS $alias" : '';
 			$join .= " ON ($primary_table.$primary_id_column = $alias.object_id)";
+			
+			if ($i) $where .= " $relationship";
+			$where .= " $alias.term_taxonomy_id $operator ($terms)";
 
-			$where .= " AND $alias.term_taxonomy_id $operator ($terms)";
-
 			$i++;
 		}
 		elseif ( 'NOT IN' == $operator ) {
@@ -592,7 +604,7 @@
 			)";
 		}
 	}
-	return compact( 'join', 'where' );
+	return compact( 'join', 'where', 'i' );
 }
 
 function _transform_terms( &$terms, $taxonomies, $field, $resulting_field ) {
