Monday, March 19, 2012

Nested query

Hey guys,
I have this query i can't seem to get to work just write. Can anyone
help me out here?
SELECT Table1.*
FROM Table1 INNER JOIN (SELECT * FROM Table2)
ON (Table1.ProvID = Table2.ProvID) AND
(Table1.VerifDate = Table2.VerifDate)
WHERE Table1.Type Like 'A%'
-Scott
When you use a query as a dynamic table like this, you have to provide an
alias for it:
SELECT Table1.*
FROM Table1
INNER JOIN (SELECT * FROM Table2) As Table2 ON (Table1.ProvID =
Table2.ProvID) AND (Table1.VerifDate = Table2.VerifDate)
WHERE Table1.Type Like 'A%'
However, I suggest just doing a straight inner join on the tables:
SELECT Table1.*
FROM Table1
INNER JOIN Table2 ON Table1.ProvID = Table2.ProvID AND Table1.VerifDate =
Table2.VerifDate
WHERE Table1.Type Like 'A%'
"Scott Elgram" wrote:

> Hey guys,
> I have this query i can't seem to get to work just write. Can anyone
> help me out here?
> SELECT Table1.*
> FROM Table1 INNER JOIN (SELECT * FROM Table2)
> ON (Table1.ProvID = Table2.ProvID) AND
> (Table1.VerifDate = Table2.VerifDate)
> WHERE Table1.Type Like 'A%'
> --
> -Scott
>
>

No comments:

Post a Comment