title: I need to avoid a cartesian product in Informix SQL
body: <p>I'm getting a cartesian product that I don't want in a complex Informix SQL query.</p>
  <p>I know which of the tables is causing the problem, but I can't figure out a way around the cartesian product.</p>
  <p>The query I refer to is very long, but I am going to exemplify the problem with only two tables:</p>
  <pre><code>SELECT ROUND( SUM( CASE WHEN ccp.IdConcepto IN ( 60, 62 ) THEN ccp.Importe END ), 2 ) TotalInvoiced
      FROM Cbts cc, Cbts_Cpts ccp
      WHERE cc.CbteId = ccp.CbteId
      AND ccp.IdConcepto IN ( 10, 30, 31, 32 )
  </code></pre>
  <p>The table called Cbtes has a primary key called CbteId, which is not the primary key of Cbtes_Cptos.
  Cbtes_Cptos also has other columns, including IdConcepto (which I use in the query), IdSubConcepto, Unidades, Importe, etc.).</p>
  <p>The problem is that in Cbtes_Cptos for the value 10 there are from 1 to 4 different records, and this difference is marked by the &quot;IdSubConcepto&quot; column, which can range from 1 to 4.
  The relationship can be the following:</p>
  <pre><code>Cbtes          Cbtes_Cptos
  IdCbte        IdCbte  IdConcepto   IdSubConcepto
  1               1        10              1
                  1        10              2
                  1        10              3
                  1        10              4
                  1        60              0
                  1        62              0
  </code></pre>
  <p>So, the query returns the sum of several times the value of &quot;Importe&quot;.</p>
  <p>And I need to use the IdConcepto in the WHERE to speed up the query since it can have more than 5000 different values.</p>
  <p>I hope I have explained the problem well, and I appreciate your attention.</p>