[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Select Statement is wrong

Posted on 2011-10-04
3
Medium Priority
?
207 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:lulu50
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Eyal earned 2000 total points
ID: 36908922
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%')
0
 

Author Comment

by:lulu50
ID: 36908963
Eyal:

Great!!!!   thank you for helping me.

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



0
 

Author Closing Comment

by:lulu50
ID: 36908968
Excellent!!!!

Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question