how can I make this tricky query run faster?

E

efandango

I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
J

Jeff Boyce

It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
E

efandango

(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


Jeff Boyce said:
It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

efandango said:
I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
E

efandango

Jeff, (anyone) can you tell me how to deal with this 'Cartesian' problem.

I can't really avoid the situation of having the two tables unjoined as the
only time they relate to each other is when I am tring to perform the
function of the query that I pasted in my previous post.

efandango said:
(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


Jeff Boyce said:
It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

efandango said:
I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
J

John Spencer

PERHAPS the following will work for you.

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Jeff, (anyone) can you tell me how to deal with this 'Cartesian' problem.

I can't really avoid the situation of having the two tables unjoined as the
only time they relate to each other is when I am tring to perform the
function of the query that I pasted in my previous post.

efandango said:
(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


Jeff Boyce said:
It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
E

efandango

John,

when I run that query I get a parameter box asking for 'Tbl_Waypoints_ID'

I'm not sure what do do?



John Spencer said:
PERHAPS the following will work for you.

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Jeff, (anyone) can you tell me how to deal with this 'Cartesian' problem.

I can't really avoid the situation of having the two tables unjoined as the
only time they relate to each other is when I am tring to perform the
function of the query that I pasted in my previous post.

efandango said:
(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


:

It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
J

John Spencer

Fix my typo. I should have type Run_WayPoint_ID in place of Tbl_Waypoints_ID


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Run_Waypoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Run_WayPoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
John,

when I run that query I get a parameter box asking for 'Tbl_Waypoints_ID'

I'm not sure what do do?



John Spencer said:
PERHAPS the following will work for you.

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Jeff, (anyone) can you tell me how to deal with this 'Cartesian' problem.

I can't really avoid the situation of having the two tables unjoined as the
only time they relate to each other is when I am tring to perform the
function of the query that I pasted in my previous post.

:

(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


:

It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
E

efandango

John,

When I run your query, it updates 5766 rows, but nothing happens, no data is
changed.

My (original) query updates 1783 rows, data is changed correctly (but
slowly...).

I noticed in the QBE window that the two In Select lines are on the two
Criteria rows (as expected) but they are each respectively one continouse
line, like this:

Line1: In (SELECT W.Run_WayPoint_ID FROM tbl_WayPoints W LEFT JOIN
tbl_Road_Restrictions R ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

Line2: In (SELECT W.Run_WayPoint_ID FROM tbl_WayPoints W LEFT JOIN
tbl_Road_Restrictions R ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


is this correct?



John Spencer said:
Fix my typo. I should have type Run_WayPoint_ID in place of Tbl_Waypoints_ID


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Run_Waypoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Run_WayPoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
John,

when I run that query I get a parameter box asking for 'Tbl_Waypoints_ID'

I'm not sure what do do?



John Spencer said:
PERHAPS the following will work for you.

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

efandango wrote:
Jeff, (anyone) can you tell me how to deal with this 'Cartesian' problem.

I can't really avoid the situation of having the two tables unjoined as the
only time they relate to each other is when I am tring to perform the
function of the query that I pasted in my previous post.

:

(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


:

It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
J

John Spencer

That will happen in the window. Access will not retain formatting very
well in SQL. Something I really don't like.

If you run just this as a query does it identify records you want to update

SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null

How about running this one does it identify records you want to update?

SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null

IF not, then I need to examine the logic I am using. Those two queries
should respectively return all tbl_WayPoints records that do not have a
match in the tbl_Road_Restrictions based on matching Run_WayPoint_ID to
the corresponding Run_WayPoint_ID_To and Run_WayPoint_Id_From values.

When you RUN the query, how are you doing so? Are you selecting Query:
Run from the menu, clicking on the Run button (Red exclamation)? If you
are simply switching views to the datasheet view, then no records will
be updated.

Do you get a message that zero records will be updated? Or that 5766
records will be updated? Or no message at all?


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

John,

When I run your query, it updates 5766 rows, but nothing happens, no data is
changed.

My (original) query updates 1783 rows, data is changed correctly (but
slowly...).

I noticed in the QBE window that the two In Select lines are on the two
Criteria rows (as expected) but they are each respectively one continouse
line, like this:

Line1: In (SELECT W.Run_WayPoint_ID FROM tbl_WayPoints W LEFT JOIN
tbl_Road_Restrictions R ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

Line2: In (SELECT W.Run_WayPoint_ID FROM tbl_WayPoints W LEFT JOIN
tbl_Road_Restrictions R ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


is this correct?



John Spencer said:
Fix my typo. I should have type Run_WayPoint_ID in place of Tbl_Waypoints_ID


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Run_Waypoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Run_WayPoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
John,

when I run that query I get a parameter box asking for 'Tbl_Waypoints_ID'

I'm not sure what do do?



:

PERHAPS the following will work for you.

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

efandango wrote:
Jeff, (anyone) can you tell me how to deal with this 'Cartesian' problem.

I can't really avoid the situation of having the two tables unjoined as the
only time they relate to each other is when I am tring to perform the
function of the query that I pasted in my previous post.

:

(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


:

It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
E

efandango

John, I feel so stupid...

your original SQL does actually work!, I didn't want to confuse things by
explaining that I actually had two original queries, one to set the matching
Waypoint_ID wherever it finds either Run_WayPoint_ID_To OR
Run_WayPoint_Id_From.

The other Query does the exact opposite and removes any rouge Waypoint_ID
flags by setting the flag to 0, this is for when I may remove any linked
records for Run_WayPoint_ID_To and Run_WayPoint_Id_From.

This was the actual SQL that i asked for help on, but was in fact testing
the other of my two queries (the add version)

This error I put down to great tiredness and tunnel vision.

Suffice it to say I offer my profound apologies and hope I I have not wasted
too much of your valuable time and perhaps made you question your abilities,
neither of which were intended. I am very grateful for your help, without
which from people such as yourselves, us novices simply flounder on the
rocks.

For the record, my query takes approx 30 secs
Yours does it in 3 secs!

thannk you.



John Spencer said:
That will happen in the window. Access will not retain formatting very
well in SQL. Something I really don't like.

If you run just this as a query does it identify records you want to update

SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null

How about running this one does it identify records you want to update?

SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null

IF not, then I need to examine the logic I am using. Those two queries
should respectively return all tbl_WayPoints records that do not have a
match in the tbl_Road_Restrictions based on matching Run_WayPoint_ID to
the corresponding Run_WayPoint_ID_To and Run_WayPoint_Id_From values.

When you RUN the query, how are you doing so? Are you selecting Query:
Run from the menu, clicking on the Run button (Red exclamation)? If you
are simply switching views to the datasheet view, then no records will
be updated.

Do you get a message that zero records will be updated? Or that 5766
records will be updated? Or no message at all?


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

John,

When I run your query, it updates 5766 rows, but nothing happens, no data is
changed.

My (original) query updates 1783 rows, data is changed correctly (but
slowly...).

I noticed in the QBE window that the two In Select lines are on the two
Criteria rows (as expected) but they are each respectively one continouse
line, like this:

Line1: In (SELECT W.Run_WayPoint_ID FROM tbl_WayPoints W LEFT JOIN
tbl_Road_Restrictions R ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

Line2: In (SELECT W.Run_WayPoint_ID FROM tbl_WayPoints W LEFT JOIN
tbl_Road_Restrictions R ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


is this correct?



John Spencer said:
Fix my typo. I should have type Run_WayPoint_ID in place of Tbl_Waypoints_ID


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Run_Waypoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Run_WayPoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

efandango wrote:
John,

when I run that query I get a parameter box asking for 'Tbl_Waypoints_ID'

I'm not sure what do do?



:

PERHAPS the following will work for you.

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

efandango wrote:
Jeff, (anyone) can you tell me how to deal with this 'Cartesian' problem.

I can't really avoid the situation of having the two tables unjoined as the
only time they relate to each other is when I am tring to perform the
function of the query that I pasted in my previous post.

:

(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


:

It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 
J

John Spencer

Great. I'm glad it is working. And I'm happy to hear that I was
correct. I wasn't doubting myself - I was doubting that I understood
your problem and what you wanted.

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

John, I feel so stupid...

your original SQL does actually work!, I didn't want to confuse things by
explaining that I actually had two original queries, one to set the matching
Waypoint_ID wherever it finds either Run_WayPoint_ID_To OR
Run_WayPoint_Id_From.

The other Query does the exact opposite and removes any rouge Waypoint_ID
flags by setting the flag to 0, this is for when I may remove any linked
records for Run_WayPoint_ID_To and Run_WayPoint_Id_From.

This was the actual SQL that i asked for help on, but was in fact testing
the other of my two queries (the add version)

This error I put down to great tiredness and tunnel vision.

Suffice it to say I offer my profound apologies and hope I I have not wasted
too much of your valuable time and perhaps made you question your abilities,
neither of which were intended. I am very grateful for your help, without
which from people such as yourselves, us novices simply flounder on the
rocks.

For the record, my query takes approx 30 secs
Yours does it in 3 secs!

thannk you.



John Spencer said:
That will happen in the window. Access will not retain formatting very
well in SQL. Something I really don't like.

If you run just this as a query does it identify records you want to update

SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null

How about running this one does it identify records you want to update?

SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null

IF not, then I need to examine the logic I am using. Those two queries
should respectively return all tbl_WayPoints records that do not have a
match in the tbl_Road_Restrictions based on matching Run_WayPoint_ID to
the corresponding Run_WayPoint_ID_To and Run_WayPoint_Id_From values.

When you RUN the query, how are you doing so? Are you selecting Query:
Run from the menu, clicking on the Run button (Red exclamation)? If you
are simply switching views to the datasheet view, then no records will
be updated.

Do you get a message that zero records will be updated? Or that 5766
records will be updated? Or no message at all?


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

John,

When I run your query, it updates 5766 rows, but nothing happens, no data is
changed.

My (original) query updates 1783 rows, data is changed correctly (but
slowly...).

I noticed in the QBE window that the two In Select lines are on the two
Criteria rows (as expected) but they are each respectively one continouse
line, like this:

Line1: In (SELECT W.Run_WayPoint_ID FROM tbl_WayPoints W LEFT JOIN
tbl_Road_Restrictions R ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

Line2: In (SELECT W.Run_WayPoint_ID FROM tbl_WayPoints W LEFT JOIN
tbl_Road_Restrictions R ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


is this correct?



:

Fix my typo. I should have type Run_WayPoint_ID in place of Tbl_Waypoints_ID


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Run_Waypoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Run_WayPoint_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

efandango wrote:
John,

when I run that query I get a parameter box asking for 'Tbl_Waypoints_ID'

I'm not sure what do do?



:

PERHAPS the following will work for you.

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.


UPDATE tbl_Waypoints
SET tbl_Waypoints.Restriction_Flag = 0
WHERE tbl_Waypoints.Run_waypoint_ID Is null
OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_FROM
WHERE R.Run_WayPoint_ID_FROM is Null)

OR Tbl_Waypoints_ID in (
SELECT W.Run_WayPoint_ID
FROM tbl_WayPoints W LEFT JOIN tbl_Road_Restrictions R
ON W.Run_WayPoint_ID = R.Run_WayPoint_ID_TO
WHERE R.Run_WayPoint_ID_TO is Null)


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

efandango wrote:
Jeff, (anyone) can you tell me how to deal with this 'Cartesian' problem.

I can't really avoid the situation of having the two tables unjoined as the
only time they relate to each other is when I am tring to perform the
function of the query that I pasted in my previous post.

:

(This form/table setup is essentially to record key intersections on certain
main roads.)

I am trying to cross reference any of 2 (sub) streets to a master address.

The main address is on a continuous form, and the other sub addresses are on
another conttinuous form. Everytime a new pair of sub addresses are created
the query checks against the master address for any occurance of either (or
both) sub addresses and flags the record accordingly with a yes/no. This
way, as I work through the various main records, I can see at a glance
whether any given main road has a relavent junction.


:

It all starts with the data ... and you haven't described it.

If you add two tables to a query and DON'T join them, you will get every
possible combination of values from table1 TIMES table2. It's called a
Cartesian Product, and is only useful in a few rare circumstances. Usually,
folks avoid it like the plague!

Can you describe a bit more about "what" you want to accomplish, rather than
"how" you think you need to do ... something?

Regards

Jeff Boyce
Microsoft Office/Access MVP

I think the problem is that two tables are not joined by any PK, which is
something that I can't do anything about. Am i stuck with a very slow
query,
or is there a solution?


UPDATE tbl_Road_Restrictions, tbl_Waypoints SET
tbl_Waypoints.Restriction_Flag = 0
WHERE (((tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_From] Or
(tbl_Waypoints.Run_waypoint_ID)<>[Run_waypoint_ID_To] Or
(tbl_Waypoints.Run_waypoint_ID) Is Null));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top