Proper syntax for named subquery - As ABC

Need help with the correct syntax to use a named subquery into another query.

AS VSI  
  SELECT VENDOR_SITE_ID
  FROM tblAll
WHERE creation_date >= ADD_MONTHS(TRUNC(SYSDATE, 'YY'), -24)
    and STATE = 'IL' ;
 
  SELECT *
  FROM VSI
  --INNER JOIN A.VENDOR_ID as
  WHERE (A.VENDOR_NAME like '%DEPARTMENT%'
  or A.VENDOR_NAME like '%ILLINOIS%');

what am I missing to call VSI as the datasource for 2nd query?

Thanks,

Karen
Karen SchaeferBI ANALYSTAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
SELECT *
  FROM VSI A
  WHERE (A.VENDOR_NAME like '%DEPARTMENT%'
  or A.VENDOR_NAME like '%ILLINOIS%');


You do not need a join.  At least there is no apparent reason from what is seen in the question. You dont even really need a cte as the where clauses coild be combined.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Karen SchaeferBI ANALYSTAuthor Commented:
This is my final results:  Thanks for the great assist.

WITH VSI AS
  (
  SELECT VENDOR_SITE_ID, STATE
  FROM tblALL
  WHERE STATE = 'IL'
  )
  SELECT S.VENDOR_NAME, A.VENDOR_SITE_ID, A.STATE
  FROM  tbl123 S
  INNER JOIN VSI A on A.VENDOR_SITE_ID = S.VENDOR_ID;  
  --WHERE (S.VENDOR_NAME like '%DEPARTMENT%'
  --    or S.VENDOR_NAME like '%ILLINOIS%');
1
PortletPaulEE Topic AdvisorCommented:
:) Now it makes more sense
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.