BETWEEN with Inner Join does not work

Asked

Viewed 284 times

1

I am having a problem when making a query using between with Internet, the query is simply not working, it returns the results as if the between was not in the query. What I’m doing wrong?

SELECT * FROM usuarios INNER JOIN matriculas ON (matriculas.idaluno = usuarios.id) WHERE matriculas.idcurso = :idcurso AND matriculas.data BETWEEN :dataini AND :datafim ORDER BY usuarios.nome ASC LIMIT 0,20

I’m putting everything straight, including the dates I’m putting on the American standard Y-m-d which is what the between operator accepts. Without using Inner Join, the query works well.

It is worth remembering that I am using.

1 answer

0

Try to do with this query:

SELECT * FROM usuarios
INNER JOIN matriculas ON matriculas.idaluno = usuarios.id AND matriculas.data BETWEEN :dataini AND :datafim
WHERE matriculas.idcurso = :idcurso
ORDER BY usuarios.nome ASC
LIMIT 0,20
  • This consultation is more wrong than my kkkk

  • Operator between has to be after Where, it doesn’t make sense the way you put it

  • @Leandrosilvacampos you are mistaken, the operator BETWEEN does not need to be after the WHERE. Do the following, put the structure and data of these two tables in Sqlfiddle: http://sqlfiddle.com/

  • look vlw for trying to help but definitely this was not the problem, because I tested the way you spoke and did not return any result that way. But I already managed to fix it, my problem was in the values of the consultation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.