0

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, 'testing1@gmail.com' UNION ALL
SELECT 2, 'testing2@gmail.com' UNION ALL
SELECT 3, 'testing3@gmail.com' UNION ALL
SELECT 4, 'testing1@gmail.com' UNION ALL
SELECT 5, 'testing3@gmail.com';

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    |
+--------------------------------+-------------------------------+
18Man
  • 572
  • 5
  • 17
  • As far as I can work out users 1 and 2 have transacted and 3,4 and 5 have not , I don't understand how you get to your desired result.. – P.Salmon Jul 15 '20 at 07:51
  • im sorry it's my bad, let me edited the expected results, thankyou anyway – 18Man Jul 15 '20 at 08:01

0 Answers0