Jump to content

Between error


alphasil

Recommended Posts

Hi

 

I need to make a quety using between because i need to check if a classroom is reserved between two differents time idtempoInicio and idTempoFim

 

this is my query

SELECT `idsala`, `idtempoInicio`, `idTempoFim`, `data` FROM `req_material_reserva` WHERE `idsala` = 3 AND `idtempoInicio` BETWEEN = 12 AND `idTempoFim` = 12 AND `data` = "2014-05-05"
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where `idtempoInicio` between = 12 AND `idTempoFim` = 12 AND `data` = "2014-05-0' at line 1
 
any help please??
Link to comment
Share on other sites

@mac_gyver, maybe I am missing something but the query and error make perfect sense.

 

@alphasil,

 

You are using BETWEEN, but you are only providing one value for the between comparison. A BETWEEN is used like this

 

 

WHERE foo BETWEEN 100 AND 200

 

Based on what you have, I think this is what you wanted

 

SELECT `idsala`, `idtempoInicio`, `idTempoFim`, `data`
FROM `req_material_reserva`
WHERE `idsala` = 3
  AND 12 BETWEEN `idtempoInicio` AND `idTempoFim`
  AND `data` = "2014-05-05"
Link to comment
Share on other sites

Hi

 

Thanks for your help

That query is not what i'm looking for

 

Before book i must check if there is any book between  'idtempoInicio' and 'idTempoFim', both are id,  those columns belongs to tempo table with the following information

 

idtempo  inicio    fim       
-------  --------  ----------
     11  08:15:00  09:00:00  
     12  09:00:00  09:45:00  
     13  10:00:00  10:45:00  
     14  10:45:00  11:30:00  
     15  11:40:00  12:25:00  
     16  12:25:00  13:10:00  
     17  13:20:00  14:05:00  
     18  14:05:00  14:50:00  
     19  15:00:00  15:45:00  
     20  15:45:00  16:30:00  
     21  16:45:00  17:30:00  
     22  17:30:00  18:15:00  

 

So i want to check if i can book between id 11 (inicio) and id 12(fim) for example, i must query the table
 
idreserva  idutilizador  idsala  idtempoInicio  idTempoFim  data        idequipamento  idfuncionario  
---------  ------------  ------  -------------  ----------  ----------  -------------  ---------------
        9          1261       4              12                       12                      2014-05-05         (NULL)           (NULL)
       10          1261       4             11                       11                      2014-05-05         (NULL)           (NULL)
       11          1261       2             11                       11                      2014-05-05         (NULL)           (NULL)
       12          1261       3             11                       11                      2014-05-09         (NULL)           (NULL)
 
Does it clear now??
Edited by alphasil
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.