开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜