Ähh, steh da gerade a wengerl auf m Schlauch, ich hab ne Tabelle, die in etwa so aussieht:
Code:
.______.______.______.
| col1 | col2 | col3 |
|------+------+------|
| abc | 1 | 2 |<
| abc | 1 | 3 |<
| xyz | 2 | 2 |
| abc | 4 | 0 |
| xyz | 1 | 1 |
| abc | 6 | 3 |<
| abc | 6 | 3 |<
'------'------'------'
Mein Problem sind die Zeilen in denen `col1` und `col2` zusammen nicht unique sind in der Tabelle (so wie die die ich oben mit "<" markiert hab). Die hätte ich gerne...
Mein Ansatz wäre etwas wie
Code:
SELECT col1,
col2
FROM tbl t1
WHERE (SELECT t2.col1
FROM tbl t2
WHERE t2.col1 = t1.col1 AND
t2.col2 = t1.col2
MINUS
SELECT DISTINCT t3.col1
FROM tbl t3
WHERE t3.col1 = t1.col1 AND
t3.col2 = t1.col2) IS NOT NULL;
aber leider scheint das DISTINCT das MINUS nicht dran zu hindern alles abzuziehen wo es passt, egal wie oft es vorkommt im zweiten.
Leider hat die Tabelle keinen Primary Key sonst ginge ja noch was wie
Code:
SELECT col1,
col2
FROM tbl t1
WHERE t1.col1 IN (SELECT t2.col1
FROM tbl t2
WHERE t2.col1 = t1.col1 AND
t2.col2 = t1.col2 AND
t2.pkey <> t1.pkey);
Ach ja alles unter Oracle, hat da wer ne Idee?
Lesezeichen