Skip to content
Advertisement

Required SQL Query

I have been stuck on this for sometime now.

I have the following SQL Tables:

department table

users table

alpha table

beta table

Explanation:

  • There’s basically a users table which has all the users.
  • Each user has a department (Dept field)
  • Each user has some records, linked to it with Uid, in alpha and beta tables.

The result I want:

I want the count of records in alpha and beta combined, grouped by Dept of the users whose records are there in these tables.

Can someone help me with the SQL query?

Advertisement

Answer

As per your table structure I’ve used dept id for retrieving result otherwise I used dept name. You can also use COALESCE function if you get NULL

Please check url http://sqlfiddle.com/#!9/020b2/1

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement