Answer the question
In order to leave comments, you need to log in
SQL. A different syntax for getting the result?
Let's say there are two tables TableA (ID INT) and TableB (ID INT, Param TINYINT).
Intersect with each other in the ID field. Table A contains unique values, table B links to a certain parameter.
The connections are just as unique. The number of links for each ID may differ.
Is there any other way to extract records from table A that have connections only with a certain set of parameters, except for this
select * from TableA a
where exists (select 1 from TableB b where b.id=a.id and b.Param in (x,y))
and not exists (select 1 from TableB b2 where b2.id=a.id and b2.Param NOT in (x,y))
Answer the question
In order to leave comments, you need to log in
select A.* from tableA A
join tableB B on B.id=A.id and B.Param in (x,y)
SELECT *
FROM TableA
WHERE ID IN
(
SELECT ID
FROM TableB
WHERE Param IN (x, y)
EXCEPT
SELECT ID
FROM TableB
WHERE Param NOT IN (x, y)
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question