Let me preface this by saying this is not a question about efficiency.
Let's say, for the sake of argument, I have a database with two tables: Users and Roles.
Users looks like this:
Username Password FirstName LastName
-------- -------- ---------- ---------
braab pass1234 Braab Himself
joe pass1257 Joe Smith
robert pass1235 Robert Irvine
kelly pass1236 Kelly Clarkson
Roles looks like this:
Username Role
-------- ----
braab admin
robert customer
kelly developer
joe admin
I want to find the first and last names of all users who have the 'admin' role.
I have two ways to achieve this: using a join or using the in clause.
IN Method:
select
firstname, lastname
from
users
where
username in
(select
username
from
roles
where
role = 'admin'
)
JOIN Method:
select
user.firstname, user.lastname
from
users as user
inner join
roles as role
on
user.username = role.username
Which way is more clear that I'm trying to find the first and last names of admin users? Is there an intended usage? To me, the in clause is the most clear in way of achieving the above goal.
Depending on your experience / training with SQL I can see this going either way. My worry is that I want other developers to be able to understand what goal I was trying to achieve.