If I have this data:
code1 code2
1 10 <-- Desired (1 appears more than once)
1 11 <-- Desired (1 appears more than once)
2 20
3 30 <-- Desired (3 appears more than once)
3 31 <-- Desired (3 appears more than once)
4 40
5 50
... And I want to write a single SQL query , the results of which are as follows:
code1 code2
1 10 <-- This result appears because 1 appears more than once above
1 11 <-- This result appears because 1 appears more than once above
3 30 <-- This result appears because 3 appears more than once above
3 31 <-- This result appears because 3 appears more than once above
(i.e. one SQL query that returns all rows for which any data in the column is code1displayed more than once) ...
What SQL can I write? Is it possible?
Here is what I still have that doesn't work:
// WARNING!
// INVALID SQL
SELECT
code1,
code2
FROM
mytable
GROUP BY code1,
code2
HAVING COUNT(code1) > 1 <
// WARNING!
// INVALID SQL
Instead of continuing to fight him ... I thought I would ask StackOverflow. Thank!
(Any MySQL-specific commands are ALLOWED if they can help.)
source
share