MySQL - Ayuda por que me muestra datos erróneos

 
Vista:
sin imagen de perfil
Val: 23
Ha aumentado su posición en 3 puestos en MySQL (en relación al último mes)
Gráfica de MySQL

Ayuda por que me muestra datos erróneos

Publicado por Pepe (10 intervenciones) el 31/08/2020 19:13:09
Hola buenas tengo esta estructura de tabla
con los siguientes datos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
--
-- Estructura de tabla para la tabla `tipo_ext`
--
 
CREATE TABLE IF NOT EXISTS `tipo_ext` (
  `id` tinyint(4) NOT NULL AUTO_INCREMENT,
  `tipo` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
 
--
-- Volcado de datos para la tabla `tipo_ext`
--
 
INSERT INTO `tipo_ext` (`id`, `tipo`) VALUES
(1, 'Numerica'),
(2, 'Larga'),
(3, 'Corta'),
(4, 'Cora');
 
-- --------------------------------------------------------
 
--
-- Estructura de tabla para la tabla `t_ag`
--
 
CREATE TABLE IF NOT EXISTS `t_ag` (
  `id` tinyint(4) NOT NULL AUTO_INCREMENT,
  `nombre` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
 
--
-- Volcado de datos para la tabla `t_ag`
--
 
INSERT INTO `t_ag` (`id`, `nombre`) VALUES
(1, 'PruebaAG1'),
(2, 'PruebaAG1'),
(3, 'PruebaAG2'),
(4, 'PruebaAG3'),
(5, 'PruebaAG4');
 
-- --------------------------------------------------------
 
--
-- Estructura de tabla para la tabla `t_ext`
--
 
CREATE TABLE IF NOT EXISTS `t_ext` (
  `id` tinyint(4) NOT NULL AUTO_INCREMENT,
  `ext` varchar(10) DEFAULT NULL,
  `tipoExt` varchar(10) DEFAULT NULL,
  `id_meg` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
 
--
-- Volcado de datos para la tabla `t_ext`
--
 
INSERT INTO `t_ex` (`id`, `ext`, `tipoExt`, `id_meg`) VALUES
(10, 'd2345', '1', '2'),
(11, 'd345534', '1', '3'),
(12, 'd344444', '2', '3'),
(13, 'd643333', '4', '4'),
(14, '45566', '3', '4');
 
-- --------------------------------------------------------
 
--
-- Estructura de tabla para la tabla `t_meg`
--
 
CREATE TABLE IF NOT EXISTS `t_meg` (
  `id` tinyint(4) NOT NULL AUTO_INCREMENT,
  `nombre` varchar(10) DEFAULT NULL,
  `id_ag` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
 
--
-- Volcado de datos para la tabla `t_meg`
--
 
INSERT INTO `t_meg` (`id`, `nombre`, `id_ag`) VALUES
(1, 'PruebaMEG1', '1'),
(2, 'PruebaMEG2', '3'),
(3, 'PruebaMEG3', '4'),
(4, 'PruebaMEG4', '4');

Quisiera saber por que me da datos incorrectos esta consulta

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
select
	t_ext.id,
    extension,
    id_meg,
    tipo_ext.tipo as tipoExtension,
    t_meg.nombre as nombreMEG,
    t_ag.nombre as nombreAG,
    t_ag.id as idAG
 
from
	t_ext
left join tipo_ext on tipo_ext.id = t_ext.tipoExt
left join t_meg on t_meg.id = t_ext.id_mg
left join t_ag on t_ag.id= t_mg.id
where t_ag.id=3

Me muestra datos del id 4, no entiendo por que me muestra los datos incorrectos. Si alguien me pudiera ayudar a ver el error que tengo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 23
Ha aumentado su posición en 3 puestos en MySQL (en relación al último mes)
Gráfica de MySQL

Ayuda por que me muestra datos erróneos

Publicado por Pepe (10 intervenciones) el 31/08/2020 21:32:59
Ya solucioné el error, no sé si está bien, pero me muestra los datos que creo que están correctos.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
select
    t_ext.id,
    extension,
    id_meg,
    tipo_ext.tipo as tipoExt,
    t_meg.nombre as nombreMEG,
    t_ag.nombre as nombreAG,
    t_ag.id as idAG
from
 t_ag
inner join t_meg on t_meg.id_ag = t_ag.id
inner join t_ext on t_ext.id_mg = t_mg.id and t_mg.id_ag = t_ag.id
inner join tipo_ext on tipo_ext.id = t_ext.tipoExt
where t_ag.id = 3
group by t_ag.id;

Intentaba mostrar las ext de la tabla t_ext segun el id de la tabla t_ag. ahora si pongo id 2 me muestra la ext que es

'3', 'PruebaAG2', '2', 'PruebaMG2', '3', '10', 'd2345', '1', '2', '1', 'Numerica'

lo malo que tuve que ir desde t_ag, buscaba una forma de ir desde t_ext, si a alguien se le ocurre cómo podría ayudarme.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar