Dear members

I try to extract some information from two mysql tables. I agree that the tables are bit weird, I have no control over the schema. Table 1 values are the column headers for the table 2. I used the following code to extract the ideal output from Table 2. I can get only the last column output, it supposed to return four column outputs. Appreciate, if you could point me where I am doing wrong.

<c:set var="strGene" value="${param.gene}" scope="request" />
<c:set var="strCompound" value="${param.Compound}" scope="request" />
<c:set var="strPkdat" value="${param.pkdat}" scope="request" />
<c:if test="${!empty strGene && !empty strCompound}">
    <sql:query var="variants" dataSource="jdbc/cplab">
            SELECT variants FROM variant WHERE UPPER(genes) = UPPER(?) <sql:param value="${param.gene}"/>
 <c:forEach var="row" items="${variants.rowsByIndex}">
    <c:forEach var="column" items="${row}">
      <c:set var="varq" value="${column}','" />
          <sql:query var="patients" dataSource="jdbc/cplab">
                 SELECT pat_id, ${varq} FROM patient_variant_table p
                 WHERE UPPER(compounds) = UPPER(?) <sql:param value="${param.Compound}"/>
                 AND UPPER(project_id_f2) LIKE UPPER('%<c:out value="${param.gene}"/>%')