Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have confusion with the following query:

Query 1:

 Select * from TABLE where vendor = "vendor1" OR  
                                    "vendor2" OR 
                                    "vendor3" AND site_status = "staus1"
 into sel

Query 2:

Select * from TABLE where ( vendor = "vendor1" OR "vendor2" 
                            OR vendor ="vendor3") 
                            AND  site_status = "staus1" 
into sel

Query 3:

 Select * from TABLE where vendor = "vendor1" OR 
                           vendor = "vendor2" OR
                           vendor ="vendor3" AND site_status = "staus1" 
 into sel

Query 4:

Select * from TABLE where (vendor = "vendor1" OR vendor= "vendor2" ) AND  
                          (site_status = "status1" OR site_status = "status2") into sel

How to find sequence of execution of query?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Well, they will all work but they will give different results - not exactly sure what result you are looking for. I would however guess that you would get the result you want using query 2 and 3 as you have have used () to "group" the Or statements together. If you don't do that you will end up "linking" the last OR with the following AND. Also instead of having a number of OR statement you could consider using the IN operator.

Select * from TABLE 
where vendor In ("vendor1", "vendor2") 
AND site_status In ("status1", "status2") 
into sel

Also have a look in the MapBasic documentation on operator precedense

share|improve this answer
    
This is better than my Query but second and fourth query gives the right result for me. –  kinkajou Aug 30 '11 at 22:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.