Jump to content
New Reality: Ads For Members ×

query with two between error


gmc1103

Recommended Posts

Hi

 

I'm having a strange error regarding the following query

SELECT COUNT(*) AS total 
            FROM `ebspma_paad_ebspma`.`req_material_reserva`
            WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = 61
            AND (((`ebspma_paad_ebspma`.`req_material_reserva`.`idtempoInicio` BETWEEN 3 AND 3) AND (`ebspma_paad_ebspma`.`req_material_reserva`.`idTempoFim` BETWEEN 3 AND 3))
            OR (`ebspma_paad_ebspma`.`req_material_reserva`.`idtempoInicio` <= 3 AND `ebspma_paad_ebspma`.`req_material_reserva`.`idTempoFim` >= 3))
            AND `ebspma_paad_ebspma`.`req_material_reserva`.`data` = "2015-10-23"

The count gives me one but my table is empty...

 

idreserva  idutilizador  idsala  idtempoInicio  idtempoFim  idequipamento  data        
---------  ------------  ------  -------------  ----------  -------------  ------------
 
 
Fields translation
 
id_booking, id:user, id_classroom, id_initialtime(timestamp), id_finaltime(timestamp), id_equipment, date
 
So what's wrong??
 
Thanks
Link to comment
https://forums.phpfreaks.com/topic/298724-query-with-two-between-error/
Share on other sites

Yes, you are correct. It does return a count of 1. So changing the query to see what it is counting gives

SELECT *  
    FROM `ebspma_paad_ebspma`.`req_material_reserva`
    WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = 61
    AND (((`ebspma_paad_ebspma`.`req_material_reserva`.`idtempoInicio` BETWEEN 3 AND 3) AND (`ebspma_paad_ebspma`.`req_material_reserva`.`idTempoFim` BETWEEN 3 AND 3))
    OR (`ebspma_paad_ebspma`.`req_material_reserva`.`idtempoInicio` <= 3 AND `ebspma_paad_ebspma`.`req_material_reserva`.`idTempoFim` >= 3))
    AND `ebspma_paad_ebspma`.`req_material_reserva`.`data` = "2015-10-23"
+-----------+--------------+--------+---------------+------------+---------------+------------+
| idreserva | idutilizador | idsala | idtempoInicio | idtempoFim | idequipamento | data       |
+-----------+--------------+--------+---------------+------------+---------------+------------+
|         3 |          719 |     61 |             3 |          3 |          NULL | 2015-10-23 |
+-----------+--------------+--------+---------------+------------+---------------+------------+

which. I believe, explains the count of 1

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.