Is there a way to use intersect without selecting distinct values only? Something like INTERSECT ALL
.
For example, consider table A and B
A --> 1, 1, 1, 2, 3, 4
B --> 1, 1, 2
Would result in
Result --> 1, 1, 2
EDIT
I think this link explains well what I want. This other link is also intersting to understand the question. Or this other link explains event better.
EDIT 2
Suppose the tables:
Table A
╔════════╦════╦═══╦════╦════╗
║ A ║ B ║ C ║ D ║ E ║
╠════════╬════╬═══╬════╬════╣
║ Car ║ 10 ║ 1 ║ OK ║ -1 ║
║ Car ║ 10 ║ 1 ║ OK ║ -1 ║
║ Car ║ 10 ║ 1 ║ OK ║ -1 ║
║ House ║ 10 ║ 1 ║ NO ║ -5 ║
║ Monkey ║ 15 ║ 1 ║ OK ║ -1 ║
║ Dog ║ 3 ║ 1 ║ OK ║ -1 ║
╚════════╩════╩═══╩════╩════╝
Table B
╔═════╦════╦═══╦════╦════╗
║ A ║ B ║ C ║ D ║ E ║
╠═════╬════╬═══╬════╬════╣
║ Car ║ 10 ║ 1 ║ OK ║ -1 ║
║ Car ║ 10 ║ 1 ║ OK ║ -1 ║
║ Car ║ 15 ║ 1 ║ OK ║ -1 ║
║ Dog ║ 3 ║ 1 ║ OK ║ -1 ║
╚═════╩════╩═══╩════╩════╝
The answer for intersect (select * from A INTERSECT select * from B
) would be:
╔═════╦════╦═══╦════╦════╗
║ A ║ B ║ C ║ D ║ E ║
╠═════╬════╬═══╬════╬════╣
║ Car ║ 10 ║ 1 ║ OK ║ -1 ║
║ Dog ║ 3 ║ 1 ║ OK ║ -1 ║
╚═════╩════╩═══╩════╩════╝
Because it takes only distinct values. What I want is taking common rows, just like:
╔═════╦════╦═══╦════╦════╗
║ A ║ B ║ C ║ D ║ E ║
╠═════╬════╬═══╬════╬════╣
║ Car ║ 10 ║ 1 ║ OK ║ -1 ║
║ Car ║ 10 ║ 1 ║ OK ║ -1 ║
║ Dog ║ 3 ║ 1 ║ OK ║ -1 ║
╚═════╩════╩═══╩════╩════╝
Observe I don't need to know what I have to link (the connection is positional, just like INTERSECT
). The ID would be something constructed using all columns (the link between table are all columns, based on their position).
INTERSECT ALL
and anEXCEPT ALL
. – Outpost