Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal estou tendo problema, com uma paginacao pois puxo do banco os
dados e devido a um representante ter mais que um telefone a query
duplica as linhas para mostrar eles o que não é legal, vou postar as
tabs e a query pra esclarecer melhor:
CREATE TABLE IF NOT EXISTS tb_representantes (idTabRep int(6) unsigned zerofill NOT NULL DEFAULT '000000',id_representante int(6) unsigned zerofill NOT NULL DEFAULT
'000000',nome varchar(50) COLLATE latin1_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (idTabRep)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO `tb_representantes` (`idTabRep`, `id_representante`,nome)(000005, 000010, 'mauro');
CREATE TABLE IF NOT EXISTS `tb_tel` (idTabtelefone int(6) unsigned NOT NULL,idCliente int(6) unsigned NOT NULL,telefone varchar(20) NOT NULL,tipo int(1) unsigned NOT NULL,idTabtelefone)) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
INSERT INTO `tb_tel` (`idTabtelefone`, `idCliente`, `telefone`,tipo) VALUES(11, 10, '11-7833-3335', 0);
(12, 10, '11-7898-8885', 1);
-- o tipo seria: 0= tel principal, 1=tel secundario; 2=cel
quando uso esta consulta que seria o normal ela duplica no caso o
registro de id 6 do joao pra mostrar os 2 tels dele isso que n
queremos :
SELECT
tb_representantes.id_representante,
tb_representantes.nome,
tb_tel.telefone
FROM tb_representantes
JOIN tb_tel ON tb_representantes.id_representante = tb_tel.idCliente
WHERE tb_representantes.id_representante =
tb_representantes.id_representante
+------------------+------------------------------+---------------+
| id_representante | nome | telefone |
+------------------+------------------------------+---------------+
| 000006 | João | 12-3413-7442 |<- joao
| 000005 | tony | 11-4786-4463 |
| 000006 | João | 12-9783-2399 |<- joao
| 000007 | Cláudio | 11-3453-5039 |
| 000008 | Yuri | 11-12121212 |
+------------------+------------------------------+---------------+
ja usei distinc left right min(tb_tel.tipo) etc
Se alguem conseguir ajudar ou alguma idéia nem que mude a estrutura do
banco pra resolver ficaria muito grato
Carregando comentários...