alphasil Posted May 3, 2014 Share Posted May 3, 2014 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?? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 3, 2014 Share Posted May 3, 2014 the query you have posted and the error message you have posted don't match. best guess is your actual query has two where keywords in it. to get programming help, you must post accurate information. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 3, 2014 Share Posted May 3, 2014 @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" Quote Link to comment Share on other sites More sharing options...
alphasil Posted May 3, 2014 Author Share Posted May 3, 2014 (edited) 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 May 3, 2014 by alphasil Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.