Rajat Sharma Rajat Sharma - 4 months ago 6
SQL Question

Search value in another SQL table

I have two tables:

tblPayroll
and
tblKPI
.

tblPayroll
is the list of all the payrolls and
tblKPI
is the list of payrolls that users have entered into the database.

Both have a column named
Payroll
.

I want to conjure a list of the Payrolls that are not entered in
tblKPI
by the users.

I don't know
JOINS
which is why I don't know where to start.

Answer

Well, if you are going to work with SQL you really should learn at least the basics, and joins are a basic part of the language.
I will show you an example that selects all records from tblPayroll that does not have a matching Payroll in tblKPI, but you know what they say - give a man a fish and he will eat for a day. Teach him how to fish and we will sit around in a bout drinking beer all day...

SELECT *
FROM tblPayroll p
WHERE NOT EXISTS
(
    SELECT 1
    FROM tblKPI k
    WHERE k.Payroll = p.Payroll
)
Comments