Tuesday, March 20, 2012

Comparing a pair

Hi
I would like to have a subquery where I'm comparing 2 values from the
subquery to the main query and unsure on the syntax. I know in Oracle sql
it's something like
WHERE (manager_id , dept_id) IN (SELECT manager_id, dept_id FROM table ...
etc)
Thanks in advance for your help
G
TSQL doesn't have row-value constructors. But EXISTS is often a better way
than using IN anyway:
SELECT *
FROM Foo
WHERE EXISTS
(SELECT *
FROM Bar
WHERE bar.manager_id = foo.manager_id
AND bar.dept_id = foo.dept_id)
David Portas
SQL Server MVP
|||ok, will try. thanks
"David Portas" wrote:

> TSQL doesn't have row-value constructors. But EXISTS is often a better way
> than using IN anyway:
> SELECT *
> FROM Foo
> WHERE EXISTS
> (SELECT *
> FROM Bar
> WHERE bar.manager_id = foo.manager_id
> AND bar.dept_id = foo.dept_id)
> --
> David Portas
> SQL Server MVP
> --
>
>

No comments:

Post a Comment