If you have a list of usernames, you can use IN
instead of =
. For example:
select * form tblPerson where Username in ('Jack', 'Jill', 'Alice', 'Bob')
If you have the list of usernames already existing in another table, you can also use the IN
operator, but replace the hard coded list of usernames with a subquery.
So for example, if you have another table called tblOtherPerson
, with the usernames stored in a column called OtherUsername
, you could do:
select * from tblPerson where Username in (select OtherUsername from tblOtherPerson)
The other way (often preferred) is to JOIN
the two tables together:
select
tblPerson.*
from
tblPerson
inner join tblOtherPerson
on (tblPerson.Username = tblOtherPerson.OtherUsername)