Avatar of lulu50
lulu50
Flag for United States of America asked on

Select Statement is wrong

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?

Open in new window

MySQL ServerSQL

Avatar of undefined
Last Comment
lulu50

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Eyal

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lulu50

ASKER
Eyal:

Great!!!!   thank you for helping me.

I never had this problem before it was driving me crazy.  



lulu50

ASKER
Excellent!!!!

Thank you
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes