Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
SQL seleccionando valores distintos del conjunto de valores en la misma tabla

Tengo la siguiente tabla como resultado de mi consulta:

 value1 name ------ ------ abc JOHN def JOHN mno JOHN mno JOHN abc JAMES abc JAMES def JAMES mno RICK

En la tabla anterior, el valor mno se repite dos veces para JOHN y el valor abc se repite dos veces para JAMES .

La consulta que utilicé está aquí:

 SELECT tc.value, tr.name FROM table1 tc, table2 tr WHERE tc.id = tr.roll ORDER BY tr.name;

El resultado que me gustaría esperar es que los valores duplicados se eliminen de cada nombre. El resultado debería ser algo como esto:

 value1 name ------ ------ abc JOHN def JOHN mno JOHN abc JAMES def JAMES mno RICK

Solo quiero eliminar el valor duplicado de cada nombre. Cómo puedo conseguir esto ?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Pruebe con distintos como se muestra a continuación y también use la unión estándar como se muestra.

 SELECT DISTINCT tc.value, tr.name FROM table1 tc INNER JOIN table2 tr ON tc.id = tr.roll ORDER BY tr.name;
over 4 years ago · Santiago Trujillo Report

0

Puede usar la palabra clave DISTINCT como ya etiquetó:

 SELECT DISTINCT t1.value, t2.name FROM table1 t1 JOIN table2 t2 ON t1.id = t2.roll ORDER BY t2.name;

o GROUP BY t1.value, t2.name cláusula, alternativamente:

 SELECT t1.value, t2.name FROM table1 t1 JOIN table2 t2 ON t1.id = t2.roll GROUP BY t1.value, t2.name ORDER BY t2.name;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!