Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Null Parameters or table with no data

Status
Not open for further replies.

lavadan

Programmer
Dec 17, 2007
49
US
I have a table StateCounty with State and County. The table can also be empty.

I want to use the values from these tables as parameter to get data from zip table like

select * from tblzip where tblZip.State in (select distinct State from StateCounty) and tblZip.County in (select distinct county from statecounty)

Now this would work as long as there is some data in the state county table. But if the statecounty table is empty, then I want all data from tblZip. How to achieve this?
 
Code:
SELECT * FROM tblzip
LEFT JOIN StateCounty ON tblzip.State = StateCounty.State AND tblzip.county = StateCounty.county

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top