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 th开发者_JAVA技巧e first two rows. What is the best way to do this?
select title, menu_id from tableName group by menu_id having count(menu_id) > 1
精彩评论