Here's one way:

create table tbl (
col1 char(1),
col2 int );

insert into tbl (col1, col2)
VALUES
("a",1),
("a",2),
("a",3),
("b",4),
("b",2),
("b",7),
("c",1),
("c",2);


select col2
from tbl
group by col2
having count(col2) >= 2
order by col2;

+------+
| col2 |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.00 sec)

Dan



John Nichel wrote:
Running MySQL 4.0.20 on a RHEL3 box.

Hi,

I'm trying to find the data in a table which is common to two or more ids. Let's say my table looks like this...

---------------
| col1 | col2 |
---------------
|  a   |  1   |
|  a   |  2   |
|  a   |  3   |
|  b   |  4   |
|  b   |  2   |
|  b   |  7   |
|  c   |  1   |
|  c   |  2   |
---------------

I'm trying to get the data in col2 that is common for col1....basically, I want it to return '2' when I do something like:

select col2 from table where col1 = 'a' || col1 = 'b' || col1 = 'c'

(obviously that select doesn't work).

I know this probably sounds confusing, but I'm can't find a better way to word it...guess that's why my Google searches turned up nothing I could use. It would be much appreciated if someone could point me to the documentation on something like this, or give me a nudge in the right direction. TIA

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to