I have three tables called: users
, facilities
, and staff_facilities
.
users
contains average user data, the most important fields in my case being users.id
, users.first
, and users.last
.
facilities
also contains a fair amount of data, but none of it is necessarily pertinent to this example except facilities.id
.
staff_facilties
consists of staff_facilities.id
(int,auto_inc,NOT NULL),staff_facilities.users_id
(int,NOT NULL), and staff_faciltities.facilities_id
(int,NOT NULL). (That's a mouthful!)
staff_facilities
references the ids for the other two tables, and we are calling this table to look up users' facilities and facilities' users.
This is my select query in PHP:
SELECT users.id, users.first, users.last FROM staff_facilities LEFT JOIN users ON staff_facilities.users_id=users.id WHERE staff_facilities.facilties_id=$id ORDER BY users.last
This query works great on our development server, but when I drop it into the client's production environment often times blank rows appear in the results set. Our development server is using the replicated tables and data that already exist on the client's production server, but the hardware and software vary quite a bit.
These rows are devoid of any information, including the three id fields that require NOT NULL values to be entered into the database. Running the query through the MySQL management tools on the backend returns the same results. Searching the table for NULL fields has not turned up anything.
The other strange thing is that the number of empty rows is changing based on the varying results caused by the WHERE clause id check. It's usually around one to three empty rows, but they are consistent when using the same parameter.
I've many times dealt with the returning of nearly duplicate rows due to LEFT JOINS, but I've never had this happen before. As far as displaying the information goes, I can easily hide it from the end user. My concern is primarily that this problem will be compounded as time passes and the number of records grows larger. As it sits, this system has just been installed, and we already have 2000+ records in the staff_facilities
table.
Any insight or direction would be appreciated. I can provide further more detailed examples and information as well.