Sql Query For My sql

10 pts.
Tags:
MySQL
SQL Query
I have two database tables Employee and salary    Where Employee maintains details about employee And the salary table maintains data about Payroll entry.             Iwant the query for Select the employees who have not got salary for a particular month I have already tried this select employee.empid , salary.empid , employee.name  from  salary  , employee where salary.month='$month' and salary.year='$year' and employee.empid!=salary.empid

Software/Hardware used:
Data base My Sql

Answer Wiki

Thanks. We'll let you know when a new response is added.

Something like this should work:

<pre>SELECT empid,name
FROM employee e
WHERE NOT EXISTS (
SELECT 1
FROM salary
WHERE empid = e.empid
AND month = ‘$month’
AND year = ‘$year’);</pre>

-CarlosDL

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Joins
    can we use joins for this concept
    10 pointsBadges:
    report
  • carlosdl
    An inner join would exclude the desired employees because they don't have a matching record in the salary table for that month. An outer join could work if you check for nulls in columns from the salary table.
    69,475 pointsBadges:
    report
  • Sqlmys
    N
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following