Please ehlp me to simplify this sql query, and please don't laugh too hard, this stuff is tricky and after weeks this works but i'm pretty sure it is **** ugly.
Here is the query from Dreamweaver
SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDA = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDB = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDC = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDD = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDE = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDF = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDG = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDH = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDI = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
UNION SELECT DISTINCT
tblcustomers.LocationsID, tblcustomers.CompanyName,
tbllocations.LocationsID, tbllocations.LocationName,
tblcatagories.CatagoriesID, tblcatagories.CatagoryName
FROM
tblcustomers, tbllocations, tblcatagories
WHERE
tblcustomers.LocationsID = tbllocations.LocationsID AND
tblcustomers.CatagoriesIDJ = tblcatagories.CatagoriesID AND
tblcustomers.AccountStatus !='offline'
ORDER BY
LocationName, CatagoryName, CompanyName
I have tried to format the code to make it easier to read on this site, I hope I have not made it harder to use though.
If you need to see what this does it is for dynamic dropdown lists on my site here
http://www.higuide.co.za.
Please let me know if more info is required, if you ot to the end of the code without giving up thank-you.