Query MYSQL with predominance of WHERE clause

0

I have the following query (after all logic, ie the final query)

SELECT *
FROM cl_assistance AS CA
LEFT JOIN cl_assistance_rel AS CREL ON CA.cod_assistance = CREL.rel_assistance
WHERE latitude
BETWEEN -24.22070591
AND -22.88033389
AND longitude
BETWEEN - 47.30349541
AND - 45.96312339

What I need help with is that in the cl_assistance_rel table there is the foreign key rel_type that references the cl_assistance_type the type of assistance. Then there are 3 support options that come in GET of the requisition "Air conditioners", "Stoves" and "Lavadouras" (in code form).

So, I need to include the query parameters:

CREL.rel_type = '1' OR
CREL.rel_type = '2' OR
CREL.rel_type = '3'

That is, first I get all the posts within the given area, then I select the ones that fit the types of assists.

In case I join these two queries, I end up picking up all the posts.

    
asked by anonymous 10.03.2015 / 21:40

1 answer

2

You need to separate the query checks according to the logic you described:

  

First I get all the posts within the given area, then I   selects the ones that fit the types of assists

SELECT *
FROM cl_assistance AS CA
LEFT JOIN cl_assistance_rel AS CREL ON CA.cod_assistance = CREL.rel_assistance
WHERE 
(latitude
BETWEEN -24.22070591
AND -22.88033389)
AND 
(longitude
BETWEEN - 47.30349541
AND - 45.96312339)
AND
(CREL.rel_type = '1')

This query will take all the assists of a certain area that gives support to the product 1.

    
11.03.2015 / 20:21