diff --git a/db/StoredProcedures.sql b/db/StoredProcedures.sql
index 9a4599fdf98ad50a5e1dc730b386d55a3fbcc6f5..dc0348243538a84f12f9d292f6ccb7be444c0eaa 100644
--- a/db/StoredProcedures.sql
+++ b/db/StoredProcedures.sql
@@ -1022,12 +1022,8 @@ BEGIN
 			( students.LastName LIKE CONCAT(Last,"%") ) AND 
 			( students.FirstName LIKE CONCAT(First,"%") ) AND
 			( students.SecondName LIKE CONCAT(Second,"%") ) AND
-			( 	disciplines_students.Type = 'detach' OR 
-				( 	disciplines_groups.ID IS NULL AND  
-					( 	disciplines_students.Type IS NULL OR
-						disciplines_students.Type != 'attach'
-					)
-				)
+			( 	( 	disciplines_students.Type IS NOT NULL AND disciplines_students.Type = 'detach'	) OR 
+				( 	disciplines_groups.ID IS NULL AND disciplines_students.Type IS NULL 	)
 			)
 
 	ORDER BY study_groups.Grade ASC, study_groups.GroupNum ASC;