Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag 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

ASKER CERTIFIED SOLUTION
Avatar of Eyal
Eyal
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

Eyal:

Great!!!!   thank you for helping me.

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



Avatar of lulu50

ASKER

Excellent!!!!

Thank you