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

259
Views
Encuentra las filas que tienen la misma columna

Quiero saber cómo hacer lo siguiente en SQL:

 SELECT * FROM table_A WHERE id IN(:myValues) AND other_colum has the same value

Por ejemplo, si tengo una tabla de conversación (iduser, idconversation), quiero una consulta SQL que devuelva algunas de las identificaciones que tienen la misma identificación de conversación. debería volver

 35;105 37;105 35;106 37;106

Con 35,37 los idUsers y 105.106 las conversaciones que tienen en común.

Para ir más allá, trabajo con Doctrine y PostegreSQL , y se genera la tabla que quiero consultar (relación de muchos a muchos), pero tengo dificultades para integrar la subconsulta.

 **public function getAllCommonConversationByUserId($ids) { return $this->createQueryBuilder('c') ->select('c.id') ->innerJoin('c.idUser', 'recievedConversation') ->where('recievedConversation IN (:ids)') ->andWhere('$qb->expr()->eq("SELECT id FROM table GROUP BY(id) HAVING COUNT(*) >1")') ->setParameter(':ids', $ids) ->getQuery() ->getResult(); }**
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Sólo:

 SELECT * FROM table_A WHERE idconversation in ('105','106') and iduser in ('35','37')

ACTUALIZACIÓN: ¿Está diciendo si la conversación de identificación está duplicada? (¿mostrando varias veces?)

Si es así:

 Select * From table where idconversation in ( Select idconversation From table group by (idconversation) Having count(*) >1 ) --where iduser in ('35','37')
over 4 years ago · Santiago Trujillo Report

0

Puede obtener las conversaciones usando group by y having :

 SELECT conversationid FROM table_A WHERE userid in (35, 37) GROUP BY userid HAVING count(distinct userid) = 2;

Si desea las filas originales, puede volver a unirse a la tabla original.

over 4 years ago · Santiago Trujillo Report

0

Intenta hacer esto:

 select id, conversation from [your table name] where conversation in ( select conversation from [your table name] where id in (35) )

Devuelve a todos los participantes de la conversación con ID de usuario = 35

Si tiene duplicados en su tabla, agregue una declaración distinta a la seleccionada.

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!