Cordial greeting, I am trying to show the data of an instant search table, the code works correctly, I had made the query in such a way that it looked for me in the whole table, until then everything is fine, but now I need to ask the query with a filter ( REGIONAL
) and I think I have to do a nested query, but it does not work for me. The idea is that when doing the search, only the records that are of the REGIONAL
of ORIENTE appear. P.D: I do not put all the code for saving, because as I said before it works correctly and for saving space.
The table I have is the following:
+--------+--------+----------+---------------+
| PLACA | CIUDAD | REGIONAL | FECHA_TANQUEO |
+--------+--------+----------+---------------+
|ABC-123 |CALI |OCCIDENTE | 2018-04-21 |
+--------+--------+----------+---------------+
|DEF-456 |BOGOTA |ORIENTE | 2018-04-20 |
+--------+--------+----------+---------------+
|GHI-789 |TUNJA |ORIENTE | 2018-04-20 |
+--------+--------+----------+---------------+
$q
is the input variable where the characters are written to perform the search.
SELECT PLACA, CIUDAD, FECHA_TANQUEO, SUM(VALOR) AS SUMA
FROM combustible
WHERE PLACA LIKE '%".$q."%' CIUDAD LIKE '%".$q."%' OR FECHA_TANQUEO LIKE '%".$q."%' AND REGIONAL = 'ORIENTE'
GROUP BY PLACA ORDER BY 'SUMA' DESC"
The previous query shows me the cities of EAST but also shows me some cities of the WEST.