TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Inner Join With Count And Case
Gagan Gautam
Jun 30, 2016
8.2
k
0
4
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
This blog shows Inner Join with count and case in SQL Server.
Here in this blog, I have discussed about inner join with count and case tutorial.
In this code I am showing how to count records in more than one table and how to use case for printing message.
select
COUNT
( * )
as
'Num of Role'
, Types = (
case
when
UserRole.Id = 1
then
'Created By Admin'
when
UserRole.Id = 8
then
'Created By Creator'
end
)
from
Model
inner
join
dbo.[
User
]
on
Model.UserId = [
User
].Id
inner
join
UserRole
on
dbo.[
User
].UserRoleId = dbo.[UserRole].Id
Group
By
UserRole.Id
Output
SQL Server
Case
Inner Join
Next Recommended Reading
Physical Join Vs Logical Join In SQL Server