Skip to content

Instantly share code, notes, and snippets.

@archsh
Created June 20, 2014 16:04
Show Gist options
  • Save archsh/5e5d2d56283120b720b6 to your computer and use it in GitHub Desktop.
Save archsh/5e5d2d56283120b720b6 to your computer and use it in GitHub Desktop.
/* A SQL get all rows with duplicated values in cols*/
/*从一个表里面查询出一个或多个字段含有同样值的SQL语句。*/
SELECT orders.* FROM risingstardb2.sales_order AS orders
LEFT JOIN ( SELECT group_concat(ids) AS ids FROM
(SELECT COUNT(*) AS num, group_concat(id) as ids
FROM risingstardb2.sales_order GROUP BY consignee_name, consignee_phone, delivery_address
HAVING COUNT(*) > 1 ) AS new_orders) AS order_ids
ON TRUE WHERE FIND_IN_SET(orders.id, order_ids.ids);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment