Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Simplifying my sql query???
Old 08-20-2007, 04:33 PM Simplifying my sql query???
Super Talker

Posts: 116
Name: Paul
Location: South Africa
Trades: 0
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.
scorpioserve is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-20-2007, 05:32 PM Re: Simplifying my sql query???
Super Talker

Posts: 130
Trades: 0
I've never seen a query that long . If you can list your schema and how and what you want extrapolated I'm positive I could simplify it for you and also explain how I do it.
__________________
flann

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
flann is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 05:42 PM Re: Simplifying my sql query???
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 385
Name: Jamie Lewis
Location: UK
Trades: 0
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.AccountStatus !='offline' AND

(
tblcustomers.CatagoriesIDA = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDB = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDC = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDD = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDE = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDF = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDG = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDH = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDI = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDJ = tblcatagories.CatagoriesID
)

ORDER BY
LocationName, CatagoryName, CompanyName

That Should Work

Jamie
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 08-20-2007, 05:57 PM Re: Simplifying my sql query???
Super Talker

Posts: 130
Trades: 0
In looking at this query, I can't help but get the feeling that the schema of your database could be improved on as well. I'd be happy to take a look for you and see if we can't improve things a bit more for you.
__________________
flann

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
flann is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 06:39 PM Re: Simplifying my sql query???
Super Talker

Posts: 116
Name: Paul
Location: South Africa
Trades: 0
Quote:
Originally Posted by JamieLewis View Post
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.AccountStatus !='offline' AND

(
tblcustomers.CatagoriesIDA = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDB = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDC = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDD = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDE = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDF = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDG = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDH = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDI = tblcatagories.CatagoriesID OR
tblcustomers.CatagoriesIDJ = tblcatagories.CatagoriesID
)

ORDER BY
LocationName, CatagoryName, CompanyName

That Should Work

Jamie
I am in shock, this worked perfectly and you did it in how long maybe 10 minutes, what took me 4 days to think up and about another 2 to actually et any where near the correct result that is amazing. Well maybe I should stop what i'm doing and go look for a manual labour job somewhere, cause I do not know how your brain must be wired to have even figured out what I was trying to achieve.

Thanks and my page load time seems quicker too.

Thanks again
scorpioserve is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 06:45 PM Re: Simplifying my sql query???
Super Talker

Posts: 116
Name: Paul
Location: South Africa
Trades: 0
Quote:
Originally Posted by flann View Post
In looking at this query, I can't help but get the feeling that the schema of your database could be improved on as well. I'd be happy to take a look for you and see if we can't improve things a bit more for you.
I would love for you to take a look at it if you would not mind, thanks for the offer, maybe you could pm me or email me direct and let me know how i can give you the information or if you could just log-in to me and take a look at how it could be improved

Thanks for all the help, for the second time in one evening.
scorpioserve is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 06:48 PM Re: Simplifying my sql query???
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 385
Name: Jamie Lewis
Location: UK
Trades: 0
Quote:
Originally Posted by scorpioserve View Post
I am in shock, this worked perfectly and you did it in how long maybe 10 minutes, what took me 4 days to think up and about another 2 to actually et any where near the correct result that is amazing. Well maybe I should stop what i'm doing and go look for a manual labour job somewhere, cause I do not know how your brain must be wired to have even figured out what I was trying to achieve.

Thanks and my page load time seems quicker too.

Thanks again
hehe, no problem, it was simply a case of grouping the conditions.

Jamie
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 08-30-2007, 05:46 PM Re: Simplifying my sql query???
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
aaaww i think Jamies blushing! (kiddin') hehe
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Simplifying my sql query???
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37234 seconds with 12 queries