Jump to content

[SOLVED] What's up with this query?


Moron

Recommended Posts

$RESULTDS=mssql_query("SELECT DISTINCT LH.[EMPNO], M2.[hrYRAT], M2.[EMPNO], M2.[MANLAP], M2.[PAYCTR], M2.[MANLAC], M2.[MANLTC], M2.[MSKLAB], M2.[MSKLTC], M2.[NAMEMI], M2.[NAMEL], M2.[NAMEF], EH.[DATE], EH.[ENETPA], EH.[EGRSER], EH.[EREGHR], EH.[EDEDUC], EH.[EROTHR], EH.[EFWHD], EH.[EPEDAT], EH.[ESSDED], EH.[EHOSPD], EH.[ELIFED], EH.[ECRUD], M2.[POSITN], M2.[MCTDWH], M2.[MHDATE], M2.[MCTDCS], M2.[MO3TOT], M2.[MCTDLD], M2.[MCTDGE], M2.[MALPPP], M2.[MSLPPP], M2.[MWHSTA], M2.[MWHALL], M2.[MWHADD], EH.[EGARND], EI.[DDEPTN], EI.[NEWOCC], EI.[hrYRAT], EI.[MEMPAD], EI.[MEMPCS], EI.[MEMPZI]

FROM LeaveHistory LH 

JOIN MASTERL2 M2 
ON LH.[EMPNO]=M2.EMPNO  JOIN EARNHIST EH
ON EH.[EEMPNO]=M2.EMPNO JOIN View_EmployeeInfo EI
ON EI.[EMPNO]=M2.EMPNO

WHERE M2.[MSSNO] = '".$_SESSION['password']."' and EH.[EPEDAT] = '8252007'

ORDER BY EH.[DATE] desc"); 

$RESULT=mssql_fetch_assoc($RESULTDS);

 

When I enter my own info, it gives me what I want. It works the same for my boss. He and I have been here for several years. But, when I enter the info for one of the newer guys, it pulls nothing.

 

I directly queried M2 WHERE their SSN (password) matches and it shows. I queried EH WHERE the new guy's record has an EPEDAT of "8252007." Yet it pulls nothing on the new guys.

 

Thoughts?

 

Link to comment
Share on other sites

The difference is that JOIN requires matching data in ALL joined tables.  LEFT JOIN requires only data in the left table.  If there is no matching data in the right table, blank data will be added.

 

Example:

 

SELECT * FROM employees JOIN phone ON (employees.empno = phone.empno)

 

If an employee has no phone number, then no data will be fetched here.  But

 

SELECT * FROM employees LEFT JOIN phone ON (employees.empno = phone.empno)

 

If an employee has no phone number, data WILL be fetched from the employees table only, and the columns from the phone table will be set to NULL.

Link to comment
Share on other sites

Have you tried printing out your query from the php script (after all variable substitutions are done), copy and paste and run it manually?

 

I had done that with each individual table. It works now. I changed my "from" statement to a table that was assured of having entries for all employees and used LEFT JOIN.

 

Thanks, everyone!

 

:)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.