2

I have three tables having following structure

Table Name : users

id        name      age
1         Alok       26
2         Ashok      28
3         Amit       25

Table Name : Departments

id        name      d_name
1         Alok       Ops
2         Amit       IT
3         Shekahr    CS

I want duplicate name with total count as following using mysql query

   total     name
   2         Alok
   2         Amit
   1         Ashok
   1         Shekhar

Please help

Thanks in Advance.

Jens
  • 67,715
  • 15
  • 98
  • 113

1 Answers1

0

Try this:

select count(*) as total,name  from (
select name from users
union 
all select * from deepartment ) as temp
group by name

Union all will merge your tables and with group by and count you should get the expected result.

Jens
  • 67,715
  • 15
  • 98
  • 113