开发者

Selecting rows with a NON-distinct foreign key

开发者 https://www.devze.com 2023-02-12 17:43 出处:网络
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 retur

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

精彩评论

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