Avatar of Johny Bravo
Johny Bravo
 asked on

Help with Sql Tables

Hello Experts,

I am creating a database (taking help from experts-exchange)
Currently I have these tables,

1.People
PeopleID
Name
isSuperAdmin

2.Society
SocietyID
SocietyName

3.SocietyPeople
PeopleID
SocietyID
IsSocietyAdmin

What I need to track is, which SuperAdmin created SocietyAdmin member.
And which SuperAdmin/SocietyAdmin creates society people.
(SuperAdmin can create member for any society while SocietyAdmin can create members for his society only)

My previous quetion is posted here,
https://www.experts-exchange.com/questions/28328699/Help-with-database.html

Thanks in advance
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon
chaau

I think you need this query:
Select SuA.PeopleID as SuperAdminID, SuA.Name as SuperAdminName,
SoA.PeopleID as SocietyAdminID, SoA.Name as SocietyAdminName
FROM People SuA INNER JOIN SocietyPeople s1 ON SuA.PeopleID = s1.PeopleID AND SuA.isSuperAdmin
INNER JOIN SocietyPeople s2 ON s1.SocietyID = s2.SocietyID
INNER JOIN People SoA ON SoA.PeopleID = s2.PeopleID AND s2.IsSocietyAdmin

Open in new window

SOLUTION
Habib Pourfard

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Johny Bravo

ASKER
Hi chaau,
Thanks for the reply.
I need to add a "CreatedBy" column to track who add the members.

(
Which SuperAdmin created SocietyAdmin
Which SocietyAdmin created SocietyMember
Which SuperAdmin created SocietyAdmin
)

How the tables should be changed?
Sara bhai

If you want to track which one is create by whom
Then need to add extra column to each table that need to be tract

CreatedBy as int
LastUpdatedBy as int
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Johny Bravo

ASKER
Thank you experts.
What will the good approach :
1. Create a log table and put the entries for tracking who made the change
or
2. Put createdby in each table

e.g,

1.News
NewsiD
Title
Desc
ValidTill
SocietyId
CreatedBy (Better if we put it here and make relation with People?)

Or put the entry in log table?

There are other table also like Events/ Request and so on
ASKER CERTIFIED SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.