Phil M Phil M -4 years ago 73
MySQL Question

mysql WHERE not working with LEFT JOIN

I have, thanks to some help, got the LEFT JOIN working but need it to show selected results based on whether the record is active or not. These are either marked Y or N in the records.

The code is

SELECT suppliers.ID, suppliers.Suppliername, suppliers.postcode, suppliers.address,
suppliers.phone, suppliers.fax, suppliers.email, suppliers.website, suppliers.imagename,
suppliers.Active, suppliers.RepID, repdetails.RepID,
repdetails.RepName, repdetails.RepEmail, repdetails.RepPhone
FROM suppliers LEFT JOIN repdetails
ON suppliers.RepID = repdetails.RepID
ORDER BY Suppliername ASC


It used to work by using the URL ?Active=Y or ?Active=N but I cannot fathom how to get this working again.

Any help would be appreciated as I'm a newbie :)

Answer Source
SELECT suppliers.ID, suppliers.Suppliername, suppliers.postcode, suppliers.address, 
    suppliers.phone, suppliers.fax, suppliers.email, suppliers.website, suppliers.imagename, 
    suppliers.Active, suppliers.RepID, repdetails.RepID, 
    repdetails.RepName, repdetails.RepEmail, repdetails.RepPhone 
FROM suppliers LEFT JOIN repdetails 
    ON suppliers.RepID = repdetails.RepID 
WHERE suppliers.Active = "y" ORDER BY suppliers.Suppliername ASC

Try this

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download