Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
Inserte el número de serie en la consulta de unión mysql

Estoy teniendo una consulta mysql usando union como

 (Select id,c1,c2,c3 from table where c1=x1 and c2=x2 ) union <<---block 1 (Select id,c1,c2,c3 from table where c1=x1 and c2=x2 ) union <<---block 2 ... (Select id,c1,c2,c3 from table where c1=x1 and c2=x2 ) union <<---block mth

que devuelve result

 id|c1|c2|c3 ------------ 1 |..|..|.. 2 |..|..|.. 3 |..|..|.. .. .. .. .. .. .. .. .. nth.. .. ..

Quiero una tabla que agregue un no que muestre el resultado obtenido de qué bloque de unión

 id|c1|c2|c3|blk --------------- 1 |..|..|..|1 2 |..|..|..|1 3 |..|..|..|2 .. .. .. ..|3 .. .. .. ..|3 nth.. .. ..|3
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Agregue 1 columna más a cada consulta con el número blk:

 (Select id,c1,c2,c3, 1 blk from table where c1=x1 and c2=x2 ) (Select id,c1,c2,c3, 2 from table where c1=x1 and c2=x2 ) ... (Select id,c1,c2,c3, <n> from table where c1=x1 and c2=x2 )
over 4 years ago · Santiago Trujillo Denunciar

0

Simplemente agregue una constante a la cláusula de selección:

 SELECT id, c1, c2, c3, 1 AS blk FROM table WHERE c1 = x1 AND c2 = x2 UNION ALL -- block 1 SELECT id, c1, c2, c3, 2 FROM table WHERE c1 = x1 AND c2 = x2 UNION ALL -- block 2 ... SELECT id, c1, c2, c3, m FROM table WHERE c1 = x1 AND c2 = x2 -- block m
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda