tags:

views:

35

answers:

2

I have a set of string & numbers that I'd like to use between databases.

the idea is that table A has a row of data with 2 values acting as a single primary key

Table B has the same 2 values of data in a single row, or it doesn't...

So...

Id like to find out how many values from Table A (2 column values in a single row) match in column B (2 column values in a single row equal to A's values)

any thoughts?

A: 

Assuming that by "databases" you mean "tables", that by "values from Table A" you mean "rows from table A", and that by "column B" you mean "table B", then:

SELECT COUNT(*) FROM TableA WHERE EXISTS
 (SELECT * FROM TableB WHERE TableB.Col1 = TableA.Col1 
  AND TableB.Col2 = TableA.Col2)
Larry Lustig
+1  A: 

I don't think you need the nested SELECT statement. This should do the trick:

SELECT
    COUNT(a.*)
FROM
    TableA a,
    TableB b
WHERE
    a.Col1 = b.Col1 AND
    b.Col2 = b.Col2
KG