I have tables A, B and C. Now table A as column A1(Primary Key), table B has column B1(Primary Key) and table C has columns A1(Foreign Key to Table A.A1), B1(Foreign Key to Table B.B1).
Now I’m writing a query which list all rows from A and B and a bit column which will be set to to 1 if a row is found matching in table C otherwise 0.
SELECT
ISNULL((SELECT CAST(1 AS BIT)
FROM C
WHERE C.A1 = A.A1 AND C.B1 = B.B1),0) AS [TAG],
A.A1,
B.B1
FROM A CROSS JOIN B
This query is producing an Subquery returned more than 1 value. error even though the query has no duplicate rows after combining the A1 and B1 columns.
try this,