I need help with fixing a sql query.My goal is for this to show the advertiser for a county regardless of which city it is located in. Please seehttp://www.explorencmountains.com/County.aspx?CountyID=7. This works fine. But I would like for the advertiser to show up under all of the towns listed under Macon County when you go to their page. It currently will only show the advertiser if the city is Franklin.
select * from Advertiser, Categories, Subcategories, County, City
where Advertiser.CategoryID=Categories.CategoryID
and Advertiser.SubcategoryID=SubCategories.Subcategory ID
and County.CountyID=City.CountyID
and Advertiser.CityID=City.CityID
and City.CountyID = '7'
and Advertiser.SubCategoryID = '27'
and Advertiser.CityID='31' -won't work unless the cityid is 32
and Approve='1'
Order By ListingType, BusinessName,City
select * from County, City
where County.CountyID=City.CountyID
and City.CountyID = '7'
and CityID='31' -Will work fine
I've restructured your query to use standard ANSI joins. Couldyou explain your query a little more. Why do you need the line inred at all? What is it supposed to be doing for you?
SELECT
*
FROM
Advertiser
INNER JOIN
Categories ON Advertiser.CategoryID=Categories.CategoryID
INNER JOIN
Subcategories ON Advertiser.SubcategoryID=SubCategories.SubcategoryID
INNER JOIN
City ON Advertiser.CityID=City.CityID
INNER JOIN
County ON County.CountyID=City.CountyID
WHERE
City.CountyID = '7' AND
Advertiser.SubCategoryID = '27' AND
Advertiser.CityID='31' AND -won't work unless the cityid is 32--Why do you need this line??
Approve='1'
ORDER BY
ListingType,
BusinessName,
City
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment