**What i need:**

I need to write some kind of IF statement inside query to pick different coordinates, **if** `table1.business_id` is equal to `1`.

**For example:**

Pick `lng` and `lat` fields from `table1` **if** `table1.business_id = 1`, else, pick `lng` and `lat` fields from `table2`.

**Query:**

```
SELECT *, 
(3959 * acos(
   cos(radians('.$cords['result']['latitude'].')) * 
   cos(radians(lat)) * cos( radians(lng) - 
   radians('.$cords['result']['longitude'].')) + 
   sin(radians('.$cords['result']['latitude'].')) * 
   sin(radians(lat))
)) AS distance 
   FROM table1 INNER JOIN table2 ON table2.id = table1.business_id 
   WHERE type <> "industry" AND '.$query.'
   HAVING distance < '.$radius.'
   ORDER BY distance LIMIT 100

```

How i can get this working? How to write technically correct query?

*Thanks for any answers.*