Help wth SQL; select of no records

I have a query:

SELECT ID FROM admin_zipcode WHERE zipcode = 11111,   where 11111 does not exist in my table.

Instead of returning no records, I would like to return a record where ID =0 for any case where the zipcode does not exist.   How can I do this?
Who is Participating?

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

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.

Scott PletcherSenior DBACommented:
    FROM admin_zipcode
    WHERE zipcode = 11111
    SELECT 0
) AS derived

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
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>I would like to return a record where ID =0 for any case where the zipcode does not exist.
In that case you need a table of all zipcodes, so it knows that 0 is a valid selection but not in the data and still should be returned, as opposed to not a valid selection.  Something like...
SELECT az.zipcode, COUNT(z.zipcode)
FROM all_zip_codes_table az
  -- The LEFT means return all values from az in the return set
  LEFT JOIN admin_zipcode z ON az.zipcode = z.zipcode   
GROUP BY az.zipcode
ORDER BY az.zipcode

Open in new window

HLRosenbergerAuthor Commented:
Terrific!  thanks.
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
Microsoft SQL Server

From novice to tech pro — start learning today.