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

184
Views
Finding rows that have the same value with Postgres

Not sure if the title is descriptive enough (sorry about the bad english), but my problem is that I need to find the rows that have the same value in all rows.

Possibly easier to understand what I actually mean with an example: I have an table that's called Catalogue with the attributes motortype, motorpart and partnumber where motortype and motorpart are VARCHAR and partnumber are int.

Some partnumbers are used in all the motortypes, and it's those partnumbers that I am interested in finding.

I'm having a hard time seeing how to solve this, so any help would be greatly appreciated!

EDIT: Sorry if the question was lackful or bad. I have updated with the table schema, some sample data and my desired results under:

CREATE TABLE Catalogue (
motortype VARCHAR,
motorpart VARCHAR,
partnumber int,
PRIMARY KEY (partnumber)
);

Sample data:

INSERT INTO Catalogue VALUES ('M1', 'Brakes', 1);
INSERT INTO Catalogue VALUES ('M2', 'Brakes', 1);
INSERT INTO Catalogue VALUES ('M3', 'Brakes', 1);
INSERT INTO Catalogue VALUES ('M1', 'Gasket', 2);
INSERT INTO Catalogue VALUES ('M2', 'Gasket', 2);
INSERT INTO Catalogue VALUES ('M3', 'Pedal', 3);

Desired result:

| motorpart | partnumber |
|-----------|------------|
| Brakes    |          1 |

Hope this was better formulated!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If there are 3 different types you can use next query:

select   motorpart
from     Catalogue
group by motorpart
having   count(distinct motortype) >= 3;

If you don't know the number:

select   motorpart
from     Catalogue
group by motorpart
having   count(distinct motortype) = (select distinct motortype 
                                      from   Catalogue);

Rextester here

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!