select from same value mysql 5.7

66 Views Asked by At

i have 2 tables, this is my fiddle https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=7009f83d39d688e38aceb781b7fdc903

CREATE TABLE users (
  ID int(10) PRIMARY KEY NOT NULL,
  email  varchar(255));
  
CREATE TABLE order_match_detail (ID int(10) PRIMARY KEY NOT NULL,
createdBy int(11),
price decimal(10,2));


INSERT INTO users(ID, email)
SELECT 1, '[email protected]' UNION ALL
SELECT 2, '[email protected]' UNION ALL
SELECT 3, '[email protected]' UNION ALL
SELECT 4, '[email protected]' UNION ALL
SELECT 5, '[email protected]';

INSERT INTO order_match_detail (ID, createdby, price)
SELECT 1, 1, 2000 UNION ALL
SELECT 2, 1, 2000 UNION ALL
SELECT 3, 2, 2000 UNION ALL
SELECT 4, 2, 3000;

select * from users;
select * from order_match_detail;




with users.id = order_match_detail.createdby

i want to find out the users_id where have same email, with this query

SELECT * FROM users INNER JOIN(
  SELECT email FROM users GROUP BY email HAVING COUNT(email) > 1 order by email)
  temp ON users.email = temp.email;

after i had this query, i want to separate each users_id with same email above where doing transaction, and not doing transaction based on order_match_detail tables, users_id with no transaction are not appear in order_match_detail table. how to separate each users_id become doing transaction and not doing transaction

expected results based on the fiddle

+--------------------------------+-------------------------------+
| users_Id  doing transaction    | users_id not doing transaction|
+--------------------------------+-------------------------------+
|                              1 |                          3    |
|                                |                          4    |
|                                |                          5    |
+--------------------------------+-------------------------------+
0

There are 0 best solutions below