troubleshooting Question

Select Statement is wrong

Avatar of lulu50
lulu50Flag for United States of America asked on
MySQL ServerSQL
3 Comments1 Solution301 ViewsLast Modified:
Hi,

My select statement is wrong and I am not sure what's wrong with it.


Here's my code

thanks
If I do this I get state id 35

SELECT ChurchTbl.ChurchID, ADS.AdsID, ADS.AdsDate,StateTbl.StateID, 
CONCAT('$', Cast(ADS.price AS DECIMAL(5,2))) AS 'price', 
SubMenu.SubMenuName, ADS.AdsStatus, ADS.Title, CityTbl.CityName, 
StateTbl.StateName, ChurchTbl.ChurchName, ADS.PathImage1, 
ADS.PathImage2, ADS.PathImage3, ADS.PathImage4, MainMenu.MainMenuName,
ADS.Body FROM MainMenu 
LEFT JOIN SubMenu ON MainMenu.MenuID = SubMenu.MenuID 
LEFT JOIN ADS ON ADS.SubCategory = SubMenu.SubMenuID 
LEFT JOIN ChurchTbl ON ChurchTbl.ChurchID = ADS.ChurchID 
LEFT JOIN CityTbl ON CityTbl.CityID = ChurchTbl.ChCityID 
LEFT JOIN StateTbl ON StateTbl.StateID = CityTbl.StateID 
where StateTbl.StateID = 35 and ADS.AdsStatus = 1

-----------------------------------------------------

If I do this I get stateid 22 even though I have it in my query to select stateid 35. 

SELECT ChurchTbl.ChurchID, ADS.AdsID, ADS.AdsDate,StateTbl.StateID, 
CONCAT('$', Cast(ADS.price AS DECIMAL(5,2))) AS 'price', 
SubMenu.SubMenuName, ADS.AdsStatus, ADS.Title, CityTbl.CityName, 
StateTbl.StateName, ChurchTbl.ChurchName, ADS.PathImage1, 
ADS.PathImage2, ADS.PathImage3, ADS.PathImage4, MainMenu.MainMenuName,
ADS.Body FROM MainMenu 
LEFT JOIN SubMenu ON MainMenu.MenuID = SubMenu.MenuID 
LEFT JOIN ADS ON ADS.SubCategory = SubMenu.SubMenuID 
LEFT JOIN ChurchTbl ON ChurchTbl.ChurchID = ADS.ChurchID 
LEFT JOIN CityTbl ON CityTbl.CityID = ChurchTbl.ChCityID 
LEFT JOIN StateTbl ON StateTbl.StateID = CityTbl.StateID 
where StateTbl.StateID = 35 and ADS.AdsStatus = 1
AND ADS.Title LIKE '%I have%' or ADS.Body LIKE '%I have%'


Is there a way reword my select so i can get the correct result stateID 35?
ASKER CERTIFIED SOLUTION
Eyal

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros