473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with fairly complex query

Hi all,

I have a problem with a query. (well, I actually have a few problems...)

Here is my query.

select FOCUS.SiteName, FOCUS.URL, OTWAdCars.* , REGION.SiteName as
RegionSite, REGION.URL as RegionUrl
from OTWSite as FOCUS
right join OTWSite as REGION
on (((REGION.Eastings >= FOCUS.Eastings - 10)
and (REGION.Eastings <= FOCUS.Eastings + 10))
and ((REGION.Northings >= FOCUS.Northings - 10)
and (REGION.Northings <= FOCUS.Northings + 10)))
right join OTWAdCars
on SiteID = REGION.ID
and ((OTWAdCars.adLocation >= 2)
or (OTWAdCars.SiteID = 1 and OTWAdCars.adLocation >= 4))
where
(FOCUS.ID = 1 or External in (0, 602944126930, 288748667206, 854969239454,
832485371888, 418635492275, 23671466569, 482286983973, 301430737751,
796819020180, 867063330985, 843854571461, 659585236304, 829099029074,
272879962942, 620381345525, 252030523924, 143574956414, 298334166197,
884781346283, 333547616524, 400867572135, 368764497317, 194954968838,
863869288183, 700810190421, 415692000349, 369433922812, 522425442804,
50352719477, 548970429743, 450125473881, 853234396932, 617546273889))
and approved = 1
and date_format(dateofexpiry, '%Y%m%d') >= date_format(now(), '%Y%m%d')
order by ExSort Desc, OTWAdCars.id desc
Let me describe what I have.

I have two tables, OTWSite and OTWAdCars.
In order to get my region, I am doing a 1 to many relationship from OTWSite
(as FOCUS) to OTWSite (as REGION) then hoping to find all items in OTWAdCars
within the region (if defined as regional items.)

However...

to add to the confusion, some (in fact, at the moment, ALL) the records are
not listed with a OTWSite.ID number (though there will be mixed) so I need
to get the items in the list of numbers (in the query, which is generated
from an earlier query). Because this is "external" data, I have an external
identifier in OTWAdCars.

I currently have about 1000 records. The query above is returning approx
3000 and taking 1.5 minutes to run (way too long).

I had shuffled it around and got it down to a more reasonable number and
much faster but
1. still too many, the result was a multiple of the numbers in brackets
times how many regions)
2. before I could save the query, my frontend to MySQL crashed.

(There are 33 items in the numbered list. Ignore 0. That is there just in
case I don't have any items for my list so that the query doesn't stop)
What I am trying to achieve.

The query above should currently return me:
1. any items in the OTWAdCars table where external in the list of numbers
2. any items in the OTWAdCars table where the item is within the region.

I don't want to have multiple rows of the same item with different FOCUS
sitenames.

Sorry it has taken long to describe. It has had me stumped for days now.

I know the region part works OK. Maybe not too efficient but it does work.

Thanks for listening. If there is any info I have missed, please let me know
and I will try and provide it.

Best regards,
Dave Colliver.
http://www.FOCUSPortals.com
--
~~
All I ask is a chance to prove that money can't make me happy.

Your community connected. http://www.ashfieldfocus.com
Get your business on the net, http://www.clickprovince.com
Collectible dolls from http://www.collectorsdolls.com
Web design, hosting, domain registration? http://www.revilloc.com is the
answer.
Tips, tricks and articles for programmers of all languages on
http://www.sourcecodecorner.com
Planning a wedding? http://www.bmcweddings.com
Advertise your car on http://www.drivingseat.com
Jul 19 '05 #1
0 1333

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave | last post by:
Hi all, I have a problem with a query. (well, I actually have a few problems...) Here is my query. select FOCUS.SiteName, FOCUS.URL, OTWAdCars.* , REGION.SiteName as RegionSite, REGION.URL...
3
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going...
4
by: Starbuck | last post by:
OK, first let me say that I am no DB person. But I have a user here who keeps getting this error whenever she does, whatever it is she does, with databases... A google search takes me to...
4
by: Derek | last post by:
Hi, I've built a rather large CGI that dumps a lot of data and a fairly complex javascript app out to the client's browser. Granted this may be poor style according to someone web design...
2
by: Betrock | last post by:
This is probably very simple, but I just can't see my way thru it..... Short version: keyed values(numeric)in a lookup table are stored in a main table. They are displayed as text values - the...
4
by: Eric E | last post by:
Hi all, I have a fairly complex form in Access 2000. In particular, it has two subforms on separate tabs of a tab control. For the last two weeks, I've encountered the dreaded : "You can't...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
9
by: Nick Locke | last post by:
I have a fairly simple structure: - Simple Types in an XSD - Complex Types (one file) in another XSD, importing the Simple Types - More Complex Types (second file) in another XSD, again...
1
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area...
1
by: Ana RM | last post by:
Mark.Powell@eds.com (Mark D Powell) wrote in message news:<2687bb95.0308010642.1fc4ff1f@posting.google.com>... Hi Mark, Thanks por answer me. I do not think it is important thw warehouse...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.