1

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?

2

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

  • This is better than my Query but second and fourth query gives the right result for me. – kinkajou Aug 30 '11 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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