Mysql query problem (subquery) difference between MYSQL versions.

Asked

Viewed 158 times

0

I have a problem in a MYSQL query, I think it is different from versions of MYSQL, my client’s database is on hostgator (Database client version: libmysql - 5.1.73 / Server version: 5.6.30 - Mysql Community Server ) , I backed up the bank and put it on my server at Locahost (Database client version: libmysql - 5.5.50 / Server version: 5.1.73-rel14.11-log ).

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 that is correct return me 4 lines.

I was able to identify that the problem is in subselect, I took only the values of subselect and put the values 4 values and worked I had no problem.

** to understand what I am doing with the subselect I have a table that has promocoes_vigencia with two dates (initial and final) and Id_promocao (fk) and another table with the name of promotion field Id (pk). the problem is that the table promocoes_vigencia has several promotions already registered, for the same customer I have to pick up only 1 record of each of these vigencias within the initial and final date. ex.

Table promotion

exemplo é o código 635

On this line I need to pick up only min(data_final) and data_initial > now

Table promotion

Tabela promocao

I have a single promotion on several different dates.

Any suggestions for this problem?

  • You checked the time difference between the servers?

  • yes the difference is 3 hours.

No answers

Browser other questions tagged

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