<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:12pt"><avglsdata id=avglsdata></avglsdata>
<DIV></DIV>
<DIV>Please, this should not be in development; it belongs in support.</DIV>
<DIV> </DIV>
<DIV>Actually, Ivan's query won't work because each skill is on a separate row. Your query, AFAICT, is the only way the way to actually find multiple skill combinations. It also has the advantage of scaling to handle even more skills. But let's make it truly Drupalized:</DIV>
<DIV> </DIV>
<DIV>SELECT e.employee_id FROM {employees} e WHERE <BR> EXISTS(SELECT 1 FROM {skills} s WHERE s.employee_id = e.employee_id AND s.skill_id = 'java')<BR>AND EXISTS(select 1 FROM {skills} s WHERE s.employee_id = e.employee_id AND s.skill_id = 'C++')</DIV>
<DIV> </DIV>
<DIV>Of course, to use it in a db_query(), you will need to further parameterize it.</DIV>
<DIV> </DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New, courier, monaco, monospace, sans-serif"> $skills_desired = array('java', 'c++', 'php'); // Values can be filled however you prefer.</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New"> $wheres = array_fill(0, count($skills_desired), "EXISTS(SELECT 1 FROM {skills} s WHERE s.employee_id = e.employee_id AND s.skill_id = '%s')");</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New"> $query = "SELECT e.employee_id FROM {employees} e WHERE " . implode(' AND ', $wheres);</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New, courier, monaco, monospace, sans-serif"></FONT> </DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New, courier, monaco, monospace, sans-serif"> if ($result = db_query($query, $skills_desired)) {</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New, courier, monaco, monospace, sans-serif"> while ($result = db_result($result)) {</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New"> // ... do something with the employee.</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New, courier, monaco, monospace, sans-serif"> }</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New, courier, monaco, monospace, sans-serif"> }</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New, courier, monaco, monospace, sans-serif"> else {</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New"> return t('No matches found.');</FONT></DIV>
<DIV><FONT color=#0000bf size=2 face="Courier New, courier, monaco, monospace, sans-serif"> }</FONT></DIV>
<P><FONT size=2 face="Courier New, courier, monaco, monospace, sans-serif"></FONT> </P>
<P><FONT size=2 face="Courier New, courier, monaco, monospace, sans-serif"><FONT size=3 face="arial, helvetica, sans-serif">This is, of course, Drupal 6 code. DBTNG can do this more efficiently.</FONT><BR><BR></FONT> </P>
<P><FONT color=#ff007f size=4 face="bookman old style, new york, times, serif"><EM><STRONG>Nancy</STRONG></EM></FONT></P>
<P> </P>
<P><FONT face="arial, helvetica, sans-serif">Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.</FONT></P>
<DIV><BR></DIV>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 12pt"><BR><FONT size=2 face=Tahoma>
<DIV style="FONT-FAMILY: Courier New, monaco, monospace, sans-serif; FONT-SIZE: 10pt">
<HR SIZE=1>
</DIV>
<DIV style="FONT-FAMILY: Courier New, monaco, monospace, sans-serif; FONT-SIZE: 10pt"><B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> David Metzler</DIV>
<DIV style="FONT-FAMILY: Courier New, monaco, monospace, sans-serif; FONT-SIZE: 10pt"></FONT><BR>Select * form employees e where <BR> exists (select 1 from skills s where s.employee_id=e.employee_id and s.skill_id = 'java')<BR>AND exists(select 1 from skills s where s.employee_id=e.employee_id and s.skill_id='C++')<BR><BR>I have heard that mysql will perform better with Ivan's query, but I haven't verified that this is the case. <BR></DIV></DIV></div></body></html>