Chiraag Mundhe
Chiraag Mundhe

Reputation: 384

Selecting rows with a NON-distinct foreign key

I have a table 'pages' that looks like this:

id  | title | menu_id
 1    'foo'      1
 2    'bar'      1
 3    'baz'      2

I'm trying to select rows whose menu_id is NOT distinct. In this example, the query should return only the first two rows. What is the best way to do this?

Upvotes: 1

Views: 412

Answers (1)

Sarfraz
Sarfraz

Reputation: 382756

select title, menu_id from tableName group by menu_id having count(menu_id) > 1

Upvotes: 1

Related Questions