473,396 Members | 1,816 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.

Query too complex. How to code not like statement properly

Novice here obviously. Anyway, I'm a bit confused about how to
approach this. I have a query against a table that I'm trying to
create. I'm trying to view all streets.type values that are null, but
then exclude those STREETNAME values that are null for the S.type but
that are really okay. The query goes like:

SELECT S.ID, S.ID2, S.PREFIX, S.STREETNAME, S.TYPE
FROM streets as S
WHERE

S.STREETNAME Not Like "*HWY110*" AND
S.STREETNAME Not Like "*HWY111*" AND
S.STREETNAME Not Like "*HWY112*" AND
S.STREETNAME Not Like "*HWY113*" AND
S.STREETNAME Not Like "*HWY114*" AND
S.STREETNAME Not Like "*HWY115*" AND
S.STREETNAME Not Like "*HWY116*" AND
S.STREETNAME Not Like "*HWY117*" AND
S.STREETNAME Not Like "*HWY118*" AND
S.STREETNAME Not Like "*HWY119*" AND

etc for about 250 more values.

AND ((S.TYPE) Is Null));
Now, once I get to about 50 of these values or so, I get "query too
complex", how can I make this happen?

TIA
Nov 13 '05 #1
11 6527
On Sat, 21 May 2005 23:07:59 -0700, ynott <yn***@hotmail.com> wrote:

Put the values in a table. Then write:
SELECT ... WHERE s.StreetName not in (select <FieldName> from
<NewTable>)

-Tom.

Novice here obviously. Anyway, I'm a bit confused about how to
approach this. I have a query against a table that I'm trying to
create. I'm trying to view all streets.type values that are null, but
then exclude those STREETNAME values that are null for the S.type but
that are really okay. The query goes like:

SELECT S.ID, S.ID2, S.PREFIX, S.STREETNAME, S.TYPE
FROM streets as S
WHERE

S.STREETNAME Not Like "*HWY110*" AND
S.STREETNAME Not Like "*HWY111*" AND
S.STREETNAME Not Like "*HWY112*" AND
S.STREETNAME Not Like "*HWY113*" AND
S.STREETNAME Not Like "*HWY114*" AND
S.STREETNAME Not Like "*HWY115*" AND
S.STREETNAME Not Like "*HWY116*" AND
S.STREETNAME Not Like "*HWY117*" AND
S.STREETNAME Not Like "*HWY118*" AND
S.STREETNAME Not Like "*HWY119*" AND

etc for about 250 more values.

AND ((S.TYPE) Is Null));
Now, once I get to about 50 of these values or so, I get "query too
complex", how can I make this happen?

TIA


Nov 13 '05 #2
Perfect. Thx

On Sat, 21 May 2005 23:24:29 -0700, Tom van Stiphout
<no*************@cox.net> wrote:
On Sat, 21 May 2005 23:07:59 -0700, ynott <yn***@hotmail.com> wrote:

Put the values in a table. Then write:
SELECT ... WHERE s.StreetName not in (select <FieldName> from
<NewTable>)

-Tom.

Novice here obviously. Anyway, I'm a bit confused about how to
approach this. I have a query against a table that I'm trying to
create. I'm trying to view all streets.type values that are null, but
then exclude those STREETNAME values that are null for the S.type but
that are really okay. The query goes like:

SELECT S.ID, S.ID2, S.PREFIX, S.STREETNAME, S.TYPE
FROM streets as S
WHERE

S.STREETNAME Not Like "*HWY110*" AND
S.STREETNAME Not Like "*HWY111*" AND
S.STREETNAME Not Like "*HWY112*" AND
S.STREETNAME Not Like "*HWY113*" AND
S.STREETNAME Not Like "*HWY114*" AND
S.STREETNAME Not Like "*HWY115*" AND
S.STREETNAME Not Like "*HWY116*" AND
S.STREETNAME Not Like "*HWY117*" AND
S.STREETNAME Not Like "*HWY118*" AND
S.STREETNAME Not Like "*HWY119*" AND

etc for about 250 more values.

AND ((S.TYPE) Is Null));
Now, once I get to about 50 of these values or so, I get "query too
complex", how can I make this happen?

TIA


Nov 13 '05 #3
Tom

Have you tried this? Is it slow? I have found "NOT IN" to be very, very
slow. For this reason I would concur with putting the values into a
table, but I would suggest using a JOIN in the SQL and a WHERE
CriteriaTable.StreetName Is Null.
But perhaps that idea is no longer relevant and SQL and JET or whatever
will optimize the NOT IN condition so that its execution is fast?

Nov 13 '05 #4
On 22 May 2005 07:25:24 -0700, "ly******@yahoo.ca" <ly******@yahoo.ca>
wrote:

I haven't specifically tried the OP's example. Your suggestion is
also valid. I would hope both perform at about the same level.

-Tom.
Tom

Have you tried this? Is it slow? I have found "NOT IN" to be very, very
slow. For this reason I would concur with putting the values into a
table, but I would suggest using a JOIN in the SQL and a WHERE
CriteriaTable.StreetName Is Null.
But perhaps that idea is no longer relevant and SQL and JET or whatever
will optimize the NOT IN condition so that its execution is fast?


Nov 13 '05 #5
Tom van Stiphout <no*************@cox.net> wrote in
news:31********************************@4ax.com:
On 22 May 2005 07:25:24 -0700, "ly******@yahoo.ca"
<ly******@yahoo.ca> wrote:

Have you tried this? Is it slow? I have found "NOT IN" to be very,
very slow. For this reason I would concur with putting the values
into a table, but I would suggest using a JOIN in the SQL and a
WHERE CriteriaTable.StreetName Is Null.
But perhaps that idea is no longer relevant and SQL and JET or
whatever will optimize the NOT IN condition so that its execution
is fast?


I haven't specifically tried the OP's example. Your suggestion is
also valid. I would hope both perform at about the same level.


Both solutions ignore the fact that the original question was about
a LIKE statement.

You could still do it with a Cartesian join using a WHERE clause
with LIKE.

SELECT DISTINCT Table1.*
FROM Table1, Table2
WHERE Table1.StreetName LIKE "*" & Table2.StreetName & "*";

The DISTINCT may or may not be required. I'm not exactly certain
about it, but I don't think it is.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #6
SELECT t1.TextValue
FROM Table1 AS t1
LEFT JOIN Table2 AS t2
ON t1.StreetName LIKE '*' & t6.StreetName & '*'
WHERE t6.StreetName Is Null;

Nov 13 '05 #7
"ly******@yahoo.ca" <ly******@yahoo.ca> wrote in
news:11**********************@g43g2000cwa.googlegr oups.com:
SELECT t1.TextValue
FROM Table1 AS t1
LEFT JOIN Table2 AS t2
ON t1.StreetName LIKE '*' & t6.StreetName & '*'
WHERE t6.StreetName Is Null;


Well, I've checked the Jet query optimizer, and it optimizes joins
and equivalent WHERE clauses exactly the same way.

I'm also not sure what purpose is served with the Not Null
condition. Wouldn't an inner join accomplish the same thing?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8
Sorry, but I'm a bit confused. I'm not getting the expected results.
First off, I want to exclude all values that are in the second
table/field called t2.streetname. However, it's not working.
Instead, I'm seeing all values in table one.


On Mon, 23 May 2005 19:25:30 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
"ly******@yahoo.ca" <ly******@yahoo.ca> wrote in
news:11**********************@g43g2000cwa.googleg roups.com:
SELECT t1.TextValue
FROM Table1 AS t1
LEFT JOIN Table2 AS t2
ON t1.StreetName LIKE '*' & t6.StreetName & '*'
WHERE t6.StreetName Is Null;


Well, I've checked the Jet query optimizer, and it optimizes joins
and equivalent WHERE clauses exactly the same way.

I'm also not sure what purpose is served with the Not Null
condition. Wouldn't an inner join accomplish the same thing?


Nov 13 '05 #9
Which query did you use?
There are syntax errors in this one:
SELECT t1.TextValue
FROM Table1 AS t1
LEFT JOIN Table2 AS t2
ON t1.StreetName LIKE '*' & t6.StreetName & '*'
WHERE t6.StreetName Is Null;
It should be:
SELECT t1.TextValue
FROM Table1 AS t1
LEFT JOIN Table2 AS t2
ON t1.StreetName LIKE '*' & t2.StreetName & '*'
WHERE t2.StreetName Is Null;

Nov 13 '05 #10
Yes, I noticed that it said t6 and change it yesterday. I'm still
getting the wrong values in the return. Anyway, here's a simplified
table to explain

SELECT T1.StreetName
FROM Table1 as t1
Left Join Table2 as t2
ON
t1.StreetName not LIKE '*' & t2.Streetname & '*';

Table1.StreetName
Main St
Jackson St
1st St

Table2.StreetName
Main St

Thus, 3 values in 1st table and only one in Second. With the Select
statement above (forget null for now to make this easier), I still get
all 3 streets returned, but I only get 2 streets (Jackson St and 1st St
since Main St was in the 2nd table and was suppose to be excluded in
the results.

Does that make sense?
TIA

Nov 13 '05 #11
SELECT t1.StreetName
FROM Table1 AS t1 LEFT JOIN Table2 AS t2 ON t1.StreetName LIKE '*' & t2.StreetName & '*'
WHERE t2.StreetName Is Null

OR (same query in fact, but other syntax)
SELECT Table1.StreetName
FROM Table1 LEFT JOIN Table2 ON Table1.StreetName LIKE '*' & Table2.StreetName & '*'
WHERE Table2.StreetName Is Null;

Arno R

<sc*******@hotmail.com> schreef in bericht news:11**********************@z14g2000cwz.googlegr oups.com...
Yes, I noticed that it said t6 and change it yesterday. I'm still
getting the wrong values in the return. Anyway, here's a simplified
table to explain

SELECT T1.StreetName
FROM Table1 as t1
Left Join Table2 as t2
ON
t1.StreetName not LIKE '*' & t2.Streetname & '*';

Table1.StreetName
Main St
Jackson St
1st St

Table2.StreetName
Main St

Thus, 3 values in 1st table and only one in Second. With the Select
statement above (forget null for now to make this easier), I still get
all 3 streets returned, but I only get 2 streets (Jackson St and 1st St
since Main St was in the 2nd table and was suppose to be excluded in
the results.

Does that make sense?
TIA

Nov 13 '05 #12

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

Similar topics

0
by: Colin Steadman | last post by:
This may be slightly off topic, but this is probably a better place to ask than an Oracle group as folk here are more likely to use the feature I'm asking about. In Toad (Quest Software) there...
1
by: rdemyan via AccessMonster.com | last post by:
My application has a table that contains information on buildings. The building data comes from another database and is imported from a spreadsheet into my application. Originally, I thought...
6
by: DeanL | last post by:
Hi All, How do you run a SELECT query from code? I know that DoCmd.RunSQL only works with action or DDF queries but I need to run a query from VBA and add variables into the query as defined by...
22
by: pbd22 | last post by:
hi. I am having probelms with an update statement. every time i run it, "every" row updates, not just the one(s) intended. so, here is what i have. i have tried this with both AND and OR and...
1
by: eighthman11 | last post by:
Hello everyone. I have a table linked to an excel spreadsheet. I have an append query based on this link table. I receive an error when I run the append query "numeric field overflow". I have...
21
by: onkar | last post by:
#include<stdio.h> int i; int i; int main(){ printf("i=%d\n",i); return 0; } Note : I am using gcc-3.4.3 on i386-redhat-linux
1
by: ezderek | last post by:
For many years if I wanted to run an action query from code, I've used code something like this --- dim qd as query dim sSQL as string dim db as database set db = currentdb() sSQL = "UPDATE...
2
ntxsoft
by: ntxsoft | last post by:
Hello everybody, I have a problem while I am trying to execute multiple query in a statement. My query like that DROP TABLE IF EXISTS query; CREATE TEMPORARY TABLE query SELECT...
2
by: dowlingm815 | last post by:
i have an complex IF statement, however, i am receving incorrect data when it becomes complex. the simple statement is ContractStatus: IIf(="Pending Legal","Pending Waiver",) additionally,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...

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.