I have a problem in a MYSQL query, I believe it is a difference of versions of MYSQL, the bank of my client is in the hostGator (Database client version: libmysql - 5.1.73 / Server version: 5.6.30 - MySQL Community Server) , I made a backup of the database and put it on my server in Locahost (Database client version: libmysql - 5.5.50 / Server version: 5.1.73-rel14.11-log) / strong>.
My query is this:
select pp.id as id_promocao, pv.id as id_vigencia, pp.titulo, pp.descricao,
DATE_FORMAT(pv.data_inicial,'%d/%m/%y - %h:%i h') as data_inicial,
DATE_FORMAT(pv.data_final,'%d/%m/%y - %h:%i h') as data_final
from promocoes_promocao pp
inner join promocoes_vigencia pv on pv.promocao_id = pp.id
where pp.ativo = 1 and pv.data_final >= DATE_ADD(NOW(), INTERVAL 3 HOUR)
and pv.id in (select p.id
from promocoes_vigencia p
where p.data_final >= DATE_ADD(NOW(), INTERVAL 3 HOUR)
group by p.promocao_id)
order by pv.data_final
on the client server (hostgator) returns me 23 lines already on my server which is the correct one I get 4 rows back.
I was able to identify that the problem is in the subselect, I just got the values from the subselect and I put the values 4 values and it worked I had no problem.
** To understand what I'm doing with the subselect I have a table that has promocode_vigencia with two dates (initial and final) and id_promotion (fk) and another table with the name of promoctions_promotion field Id (pk). the problem is that the promotions_vigencia table has several promotions already registered, for the same client I have to pick up only 1 record of each of these vigencias within the initial and final date. ex.
Table promoccupations
InthislineIneedtogetonlythemin(data_final)andstart_date>now
Tablepromotions_promotion
I have a single promotion on several different dates.
Any suggestions for this problem?