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

247
Views
Find the rows that has the same column

I want to know how to do the following in SQL :

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

For example, if i've a conversation table(iduser,idconversation), I want SQL query that returns some of Ids that have the same conversation id. It should return

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

With 35,37 the idUsers and 105,106 the conversations they have in common.

To go further, i work with Doctrine and PostegreSQL, and the table that I want to query is generated (many to many relation) but i've difficulty to integrate sub-query.

  **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

Just:

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

UPDATE: Are you saying if the idconversation is duplicate? (showing multiple times?)

If so:

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

You can get the conversations using group by and having:

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

If you want the original rows, you can join back to the original table.

over 4 years ago · Santiago Trujillo Report

0

Try to do this:

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

It return all of the participants of the conversation with user id = 35

If you have duplicates in your table, please add distinct to select statement.

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!