<br>&nbsp;&nbsp; Rajesh,<br><br>&nbsp;&nbsp;&nbsp; See my previous e-mail, but just to complement, note that the equivalent translation of your SQL query:<br><br>select * from Students s where exists ( <br>&nbsp;&nbsp;&nbsp; select * from Modules m where m.student_name
 = <a href="http://s.name">s.name</a> and m.score &lt; 40 <br>)<br><br>&nbsp;&nbsp; To a rule is:<br><br>rule XXX<br>when<br>&nbsp;&nbsp;&nbsp; $s : Student( $name : name )<br>&nbsp;&nbsp;&nbsp; exists Modules( studentName == $name, score &lt; 40 )<br>then<br>&nbsp;&nbsp; // do something
<br>end<br><br>&nbsp;&nbsp;&nbsp; Hope it helps,<br><br>&nbsp;&nbsp; []s<br>&nbsp;&nbsp; Edson<br><br><div><span class="gmail_quote">2007/5/31, Rajesh.Sachin10 &lt;<a href="mailto:rajesh_sachin10@yahoo.co.in">rajesh_sachin10@yahoo.co.in</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>Following is the Example taken form the following URL:<br><br><a href="http://labs.jboss.com/file-access/default/members/jbossrules/freezone/docs/3.0.1/html_single/index.html#d0e2144">http://labs.jboss.com/file-access/default/members/jbossrules/freezone/docs/3.0.1/html_single/index.html#d0e2144
</a><br><br>But this rule is not working for me. If anyone know the logic behind the<br>rule, please explain me.<br><br>Example:<br><br>Imagine we have two classes - Student and Module. Module represents each of<br>the courses the Student attended for that semester, referenced by the List
<br>collection. At the end of the semester each Module has a score. If the<br>Student has a Module score below 40 then they will fail that semester - the<br>existential quantifier can be used used with the &quot;less than 40&quot; open
<br>proposition to check for the existence of a Module that is true for the<br>specified criteria.<br><br>public class Student {<br>&nbsp;&nbsp;&nbsp;&nbsp;private String name;<br>&nbsp;&nbsp;&nbsp;&nbsp;private List modules;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;...<br>}<br>public Class Module {
<br>&nbsp;&nbsp;&nbsp;&nbsp;private String name;<br>&nbsp;&nbsp;&nbsp;&nbsp;private String studentName;<br>&nbsp;&nbsp;&nbsp;&nbsp;private int score;<br>Java is Turing complete in that you can write code, among other things, to<br>iterate data structures to check for existence. The following should return
<br>a List of students who have failed the semester.<br><br>List failedStudents = new ArrayList();<br><br>for ( Iterator studentIter = students.iterator(); studentIter.hasNext() {<br>&nbsp;&nbsp;&nbsp;&nbsp;Student student = ( Student ) studentIter.next
();<br>&nbsp;&nbsp;&nbsp;&nbsp;for ( Iterator it = student.getModules.iterator(); it.hasNext(); ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Module module = ( Module ) it.next();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( module.getScore() &lt; 40&nbsp;&nbsp;) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;failedStudents.add( student ) ;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br>Early SQL implementations where not Turing complete as they did not provide<br>quantifiers to asses the structure of data. However modern SQL engines allow<br>nesting of SQL which can be combined with keywords like &#39;exists&#39; and &#39;in&#39;:
<br>The following query would return a set of Students who have failed the<br>semester.<br><br>select<br>&nbsp;&nbsp;&nbsp;&nbsp;*<br>from<br>&nbsp;&nbsp;&nbsp;&nbsp;Students s<br>where exists (<br>&nbsp;&nbsp;&nbsp;&nbsp;select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br>&nbsp;&nbsp;&nbsp;&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Modules m<br>&nbsp;&nbsp;&nbsp;&nbsp;where
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m.student_name = <a href="http://s.name">s.name</a> and<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m.score &lt; 40<br>)<br><br>rule<br>&nbsp;&nbsp;&nbsp;&nbsp;when<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exists( $student : Student() &amp;&amp; Module( student == $student, score &lt;<br>40 ) )
<br><br>--<br>View this message in context: <a href="http://www.nabble.com/Logic-behind-the-Rule-tf3848998.html#a10902431">http://www.nabble.com/Logic-behind-the-Rule-tf3848998.html#a10902431</a><br>Sent from the drools - user mailing list archive at 
<a href="http://Nabble.com">Nabble.com</a>.<br><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br>&nbsp;&nbsp;Edson Tirelli<br>&nbsp;&nbsp;Software Engineer - JBoss Rules Core Developer<br>&nbsp;&nbsp;Office: +55 11 3529-6000<br>&nbsp;&nbsp;Mobile: +55 11 9287-5646
<br>&nbsp;&nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>