Note that there are some explanatory texts on larger screens.

plurals
  1. POFind row-sets with mismatched values without large self join?
    primarykey
    data
    text
    <p>I have a table like this (basic example, not the real thing):</p> <pre><code>FKEY | NAME | ATTRIBUTE_X -------------------------- 1 '...' 42 1 '...' 42 1 '...' 42 2 '...' 7 2 '...' 7 5 '...' 42 5 '...' 42 5 '...' 42 5 '...' 42 6 '...' 300 6 '...' 300 .... </code></pre> <p>Where - normally - each of the attribute_x values for a given fkey are all the same. (In my real data, I calculate attribute_x from some columns in the table and this property needs to be the same for all rows with the same fkey.</p> <p>Now I have some rows where this property does not hold. I want to search the whole table to find all FKEYs with mismatched attribute_x values.</p> <p>Example:</p> <pre><code>-------------------------- 145678973 '...' 23 145678973 '...' 22 // Error, should also be 23 145678973 '...' 23 </code></pre> <p>My naive approach was:</p> <pre><code>SELECT distinct(TX1.FKEY) FROM TABLEX TX1, TABLEX TX2 WHERE TX1.FKEY=TX2.FKEY AND TX1.ATTRIBUTE_X &lt;&gt; TX2.ATTRIBUTE_X ; </code></pre> <p>But with my real data this doesn't complete (I ran of of temp tablespace and after the DBA increased the temp tablespace to 20 GIG the query ran for a few hours and then bailed out.)</p> <p>Generally, is there a more efficient query for this?</p> <hr> <p>I have a solution with PL/SQL where I just loop over the table sorted by FKEY, and if I find a different attribute_x vs. the last fetched record where the fkey stayed the same, I have found an erroneous fkey.</p> <p>But this seems oh so primitve :-) Is there an efficient pure SQL solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload