Jump to content

query with two between error


gmc1103
Go to solution Solved by Barand,

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
Edited by gmc1103
Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.